Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with renaming/moving files

Status
Not open for further replies.

brainchild1977

Programmer
Feb 1, 2005
9
US
I need to rename files by changing only the file extension (retain the filename) using a for loop. i found this piece of code online

OLDPREFIX=aaa
NEWPREFIX=bbb
for FILE in "$OLDPREFIX"*
do
NEWNAME=´echo "$FILE" | sed -e "s/^${OLDPREFIX}/$NEWPREFIX/"´
mv "$FILE" "$NEWNAME"
done

But when i run the code, i get an error saying "cannot access aaa" any ideas why?

Let me know if you have a simpler way of doing this?
 
Your sed command is looking for aaa at the front of the filename, that's what the "^" does.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top