Re: [opensuse] Bash - sed variable help needed
- From: "Theo v. Werkhoven" <theo@xxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 16 Aug 2008 11:50:13 +0200
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
- Follow-Ups:
- Re: [opensuse] Bash - sed variable help needed
- From: David C. Rankin
- Re: [opensuse] Bash - sed variable help needed
- References:
- [opensuse] Bash - sed variable help needed
- From: David C. Rankin
- Re: [opensuse] Bash - sed variable help needed
- From: David C. Rankin
- [opensuse] Bash - sed variable help needed
- Prev by Date: [opensuse] Re: Messages from opensuse@opensuse.org to you have been bouncing
- Next by Date: Re: [opensuse] Re: Messages from opensuse@opensuse.org to you have been bouncing
- Previous by thread: Re: [opensuse] Bash - sed variable help needed
- Next by thread: Re: [opensuse] Bash - sed variable help needed
- Index(es):
Relevant Pages
|