--- Begin Message ---
Subject: |
Re: File renaming using SED in BASH |
Date: |
Tue, 30 Sep 2008 16:21:42 +0200 |
User-agent: |
Thunderbird 2.0.0.16 (X11/20080723) |
MisterMuv wrote:
Hi,
I am having a problem renaming a files using SED.
The filenames are in the following format: eg
001 - GreatPics1 (The Opening) (www.somewhere.net).jpg
002 - GreatPics2 (The Closing) (www.somewhere.net).jpg
003 - GreatPics3 (The Ending) (www.somewhere.net).jpg
I am wanting to remove contents of the second parenthesis, i.e.
"(www.somewhere.net)".
So the files would end up like:
001 - GreatPics1 (The Opening) .jpg
002 - GreatPics2 (The Closing) .jpg
003 - GreatPics3 (The Ending) .jpg
This is what I have so far.
If I use this to test all is well
for f in *
do
echo $f |sed 's:(www.somewhere.net)::'
done
However when I incorporate the mv command all isn't well.
for f in *
do
chg=echo $f |sed 's:(www.somewhere.net)::'
mv $f $chg
done
I get:
bash: 001: command not found
mv: target `(www.somewhere.net).jpg' is not a directory
bash: 002: command not found
mv: target `(www.somewhere.net).jpg' is not a directory
bash: 003: command not found
mv: target `(www.somewhere.net).jpg' is not a directory
What am I doing wrong?
Thankyou all in advance.
Or use rename:
rename \(www.www.somewhere.net\).jpg .jpg *.jpg
I think this is fastest and clearest.
--- End Message ---