Scripting to convert underscores to spaces

Greetings,

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

Regards,
Bryan

Clue:
Watch:
ant:/home/vbe/script $ mv tt titi tata
Usage: mv [-f] [-i] [-e warn|force|ignore] f1 f2
mv [-f] [-i] [-e warn|force|ignore] f1 ... fn d1
mv [-f] [-i] [-e warn|force|ignore] d1 d2
Why?

And now:
ant:/home/vbe/script $ mv tt titi\ tata
ant:/home/vbe/script $ ll titi*
-rw-rw-r-- 1 vbe bin 246 Sep 10 14:05 titi tata

I let you continue...
Good luck

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.

Regards,
Bryan

Why not...

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

If your shell supports parameter substitution use:

for i in *foo*
  do 
    mv  "$i" "${i//_/ }"
  done

else

for i in *foo*
  do 
   mv  "$i" "$(echo "$i" | sed 's/_/ /g')"
  done

I should not use filenames with spaces... and the use of the -r option of read forebodes little good.:eek:
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

Regards

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... :frowning: Sorry for wasting the board's time. I'll do better next time...

Thanks for everyone's help...