Re: [opensuse] Bash - sed variable help needed



Sat, 16 Aug 2008, by drankinatty@xxxxxxxxxxxxxxxxxx:

David C. Rankin wrote:
Listmates,
What I want to do is something like:
for i in $(ls); do
ORIG_FNAME=$i
NEW_FNAME=$(echo $i | sed -e 's/^100/`date +%Y%m%d`/')
This is where the trouble comes in. I can't see a way to accomplish
this. Anybody have any ideas? I guess I could turn the problem around and
grab the numerical part on the right side of the _ with sed and then
concatenate the date to that. However, if this is a way to work a variable
into sed, that would be great. Any ideas?

I took the easy way out...

for i in $(ls); do

ORIG_FNAME=$i
PICNUM=$(echo $i | sed -e 's/^100//')

NEW_FNAME="$TODAY$PICNUM"
mv $ORIG_FNAME $NEW_FNAME

There is a tool for this you know (not surprisingly, this is
Linux..), look at exiftool(1)

I think you could use one of these examples from the manpage.

exiftool '-FileName<CreateDate' -d %Y%m%d_%H%M%S%%-c.%%e dir
Rename all images in "dir" according to the "CreateDate" date and
time, adding a copy number with leading '-' if the file already
exists ("%-c"), and preserving the original file extension (%e).
Note the extra '%' necessary to escape the filename codes (%c and
%e) in the date format string.

exiftool -r '-FileName<CreateDate' -d %Y-%m-%d/%H%M_%%f.%%e dir
Both the directory and the filename may be changed together via
the "FileName" tag if the new "FileName" contains a '/'. The
example above recursively renames all images in a directory by
adding a "CreateDate" timestamp to the start of the filename, then
moves them into new directories named by date.

exiftool '-FileName<${CreateDate}_$filenumber.jpg' -d %Y%m%d dir/*.jpg
Set the filename of all JPG images in the current directory from
the CreateDate and FileNumber tags, in the form "20060507_118-1861.jpg".

Theo
--
Theo v. Werkhoven Registered Linux user# 99872 http://counter.li.org
ICBM 52 13 26N , 4 29 47E. + ICQ: 277217131
SUSE 10.3 + Jabber: muadib@xxxxxxxxxxxxxxxx
Kernel 2.6.22 + See headers for PGP/GPG info.
Claimer: any email I receive will become my property. Disclaimers do not apply.
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx



Relevant Pages

  • Re: Image converting
    ... S> I have a large amount of jpg images having 1600 x 1200 dimension. ... S> I want to resize the images to 640 x 480 ... S> I am Unable to choose another filename extension. ... S> totalt 3.9M ...
    (comp.os.linux.misc)
  • Image converting
    ... I have a large amount of jpg images having 1600 x 1200 dimension. ... I want to resize the images to 640 x 480 ... I am Unable to choose another filename extension. ... totalt 3.9M ...
    (comp.os.linux.misc)
  • Re: [opensuse] Bash - sed variable help needed
    ... I think you could use one of these examples from the manpage. ... and preserving the original file extension. ... Both the directory and the filename may be changed together via ... Set the filename of all JPG images in the current directory from ...
    (SuSE)
  • IEs default for Save As Type incorrect
    ... I've been having trouble with IE and getting it to recognize ... correct filename showing in the Filename box, and if I choose the All ... Files option from the Save As Type drop down then the file is saved ...
    (microsoft.public.inetserver.asp.general)
  • io
    ... copy of my binary files. ... Txt are being copied with no trouble but when it ... java.io.FileInputStream+ filename); ... Please advise of where I am making a mistake or what other class and how ...
    (comp.lang.java.databases)