Re: [SLUG] LINUX character parsing problem.

From: leebc (blee2@tampabay.rr.com)
Date: Mon May 10 2010 - 13:01:25 EDT


Thus Ron Youvan hast written on Sun, May 09, 2010 at 10:23:54PM +0000, and, according to prophecy, it shall come to pass that:
> PreNameA=$(grep -a -A1 Ver.1.00 $FileName | cut -b 160-172 ) > /dev/null
<snip><snip>

> A line from a typical image file: (these are all Nikon *.nif files)
> <
> ...t.2...........J.......................i.........à.%.........H...........Ì..........................NIKON
> CORPORATION...NIKON D90......,.......,....Ver.1.00 ...2010:04:14
> 12:21:28...û\..ûÔ...........ÿ.......
>
> Immediately following the "Ver.1.00" is "2010:04:14 12:21:28" the date
> and time information in the order that I wish to use, year, month and day,
<snip>

> My problem is that I want to use "so many characters" after the "Ver.1.00"
> not "so many characters after the beginning of the greped line," (which
> sometimes is different) but cut works based on "so many character after the
> start of the line."
>
> How can I select N characters after the "Ver.1.00" in a greped line?

I'm a little surprised that someone hasn't already replied with "Use Awk
to XYZ..." ;-)
I'm a grep person.

I was trying to do something similar a couple months back to fix photos
off my cell phone which are named in a nearly useless to me MMDDYY format.

This doesn't *actualy* answer your question, but should lead you to a
solution...

The data you're looking at is (most likely) the EXIF tags.
http://en.wikipedia.org/wiki/Exchangeable_image_file_format

Debian includes the "exiftags" package which allows for the easy
retrieval of the ExIF tags.

When I use the command:
> exiftags -i dsc08759.jpg |grep "Image Created:"
I get back
        exiftags: maker note not supported
        Image Created: 2010:04:24 19:26:00

and
> exiftags -i dsc08759.jpg |grep "Image Created:" |cut -c16-
returns
        exiftags: maker note not supported
        2010:04:24 19:26:00

The first line is stderror, so
> mydate=`exiftags -i dsc08759.jpg |grep "Image Created:" |cut -c16-`
        exiftags: maker note not supported
> echo $mydate
        2010:04:24 19:26:00
works.

I recommend not using ":"'s in filenames.

I note that you were using the "-b" flag in your cut command for "bytes",
whereas I'm using the "-c" flag for "characters".
This might be part of your problem, I'm not sure, but it's possible
there is a stray null someplace. It could also be a difference in any
of the field values; maybe orientation if this example is the correct order:
        http://en.wikipedia.org/wiki/Exchangeable_image_file_format#Example

You can use the od (Octal Dump) command to view the raw contents of a
file. Use "od -c $filename | less" (or more or whatever.)
This will show something like:

0000000 377 330 377 341 321 261 E x i f \0 \0 I I * \0
0000020 \b \0 \0 \0 \f \0 016 001 002 \0 \t \0 \0 \0 236 \0
0000040 \0 \0 017 001 002 \0 006 \0 \0 \0 274 \0 \0 \0 020 001
        <snip>
0000300 \0 \0 \0 \0 \0 \0 \0 \0 S O N Y \0 \0 \0
0000320 \0 \0 \0 \0 \0 \0 \0 \0 D S L R - A 3 0
0000340 0 \0 H \0 \0 \0 001 \0 \0 \0 H \0 \0 \0 001 \0
0000360 \0 \0 D S L R - A 3 0 0 v 1 . 0
0000400 0 \0 2 0 1 0 : 0 4 : 2 4 1 9 :
0000420 2 6 : 0 0 \0 P r i n t I M \0 0 3
        <snip>

If you read between the columns, you can find the date. You'll also see a
whole bunch of nulls. Entires prefixed with "\" are escapes.

Often when dealing with binary files, od is one of the ONLY ways to
usefully view them.
I once had a file where I was trying to grep for a the string "ERROR".
Grepping for "E" would return the line, but nothing longer would. When
I finally ran the file through od I found that there were nulls between
EVERY character.
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 15:22:52 EDT