On 2008-09-21, 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)::'
That assigns echo to $chg and tries to execute $f. Use command substitution. > mv $f $chg > done for f in * do chg=$( echo "$f" | sed 's:(www.somewhere.net)::' ) mv "$f" "$chg" done -- Chris F.A. Johnson, webmaster <http://Woodbine-Gerrard.com> =================================================================== Author: Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)