Skip to the links

Call Me Al

My MozBlog

I need a little help renaming files. I have fileNameIn and I want to pass it through a regex to clean it to make fileNameOut. That part is easy enough.

Source: 041 - Beatles_-_Long and Winding Road.Mp3
Clean it: sed -e 's/^[0-9\. \-]*//' -e 's/_/ /g' -e 's/mp3/mp3/gi'
Output: Beatles - Long and Winding Road.mp3

So I have the source string and the target string, but how do I get them both in my output string? CTho suggested I use sed to duplicate the line.

sed -e 's/.*/mv & &/'
But then I need to make sure I only work on the second one. I could put in a dummy item to identify it.
sed -e 's/.*/mv & 666&/'

I've also tried doing it all inside a bash script that does its own looping.

for file in `ls 0*`;
do
stuff
done
however, that breaks a single line up at all of the spaces, so one row isn't treated as a single string.

I like CTho's idea, but my regex-fu isn't good enough.

0 comments - Post a Comment


powered by blogger