I used a script that renamed my file eg 'echo webutil.olb | tr [A-Z] [a-z]' i wanted to rename it back to webutil.olb. How do i do this for many other files that i have

link|improve this question
1  
Does the file name literally contain those strings or did you change it from or to upper or lower case and want to change it back? – Dennis Williamson May 11 '10 at 12:33
feedback

3 Answers

Debian rename allows you to specify a sed substitution pattern to apply against filenames in order to rename them.

link|improve this answer
if you've installed perl this is often supplied by prename (a version of the classic rename.pl script), so the transform is perl instead of sed. – quack quixote May 11 '10 at 9:50
feedback

Assuming that the files got renamed with the extra strings, this would probably help:

for file in echo*
do
    new="${file#* }"    # strip up to the first space (remove "echo ")
    new="${new% |*}"    # strip the space-pipe and after (remove " | tr ...")
    mv "$file" "$new"
done

This will rename, for example, a file named literally "echo webutil.olb | tr [A-Z] [a-z]" to be named "webutil.olb" and will work for other files similarly named. It expects the wanted names to be between a space and a space followed by a pipe.

link|improve this answer
feedback

For your example, tr left webutil.olb as it was.

In general, you can't do this, since you lose the information about case. For example, the filename "webutil.olb" might come from applying tr to "WebUtil.olb" or "WEBUTIL.olb".

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.