Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|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

3 Answers 3

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

share|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

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.

share|improve this answer

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".

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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