I have a bunch of music files that I want to strip the underscores out, and leave only spaces. All that I've found on the web is how to add underscores to files that have spaces, and reversing the "tr" command does not make a difference.
Here is how to convert spaces to underscores:
#!/bin/sh
ls | while read -r FILE
do
mv "$FILE" `echo $FILE | tr ' ' '_' `
done
I am able to strip the underscores by typing:
ls | while read -r FILE
do
mv "$FILE" `echo $FILE | tr -d '_'`
done
This gets rid of the underscores, but then there are no spaces in the filename (ex. 01_foo becomes 01foo).
The command to change underscores to spaces still eludes me.
Can you help me, or point me in the right direction...
okay, now, how would one do that in a script? I do not have a "rename" command, as I am using OpenBSD. My "mv" command does not even have a "-e" switch
Would there be a way using "sed" vice "tr". I need this automated. I know how to use the escape "\" for spaces, but I have dynamic filenames.
> echo "Paradise_By_The_Dashboard_Lights" | tr "_" " "
Paradise By The Dashboard Lights
However, I would express caution at not having some character other than a space in a filename. It can sometimes make file maintenance more cumbersome and also create strange filenames when they are downloaded to another system (you might see something like Paradise%20By%The...)
I should not use filenames with spaces... and the use of the -r option of read forebodes little good.
But...if you want to replace the underscores of the filenames with spaces this should be suffice:
#!/bin/sh
ls *_* | while read -r FILE
do
mv "$FILE" `echo "$FILE" | tr '_' ' '`
done
rubin, the "sed" solution seems the simplest... I was hoping to use "tr" for the solution. I guess I need to get out a "sed" tutorial and study up a little. You know, I got on so focused on figuring this out, that I'm not even sure if I need this now... Sorry for wasting the board's time. I'll do better next time...