Author Topic: Script to replace "_" with blank spaces  (Read 822 times)

musonio

  • Guest
Script to replace "_" with blank spaces
« on: September 03, 2009, 05:01:01 AM »
allmighty-old-polack provided a tip to change blank spaces in filenames (or directory names) to "_" (I don't know the name of that damn ugly character):
http://www.pclinuxos.com/index.php?option=com_smf&Itemid=26&topic=61747.msg498315#msg498315

I had been looking for a way to do the opposite for a long time.
I hate filenames with _ in them, so I modified his suggestion to the following:

I created an empty text file and pasted:

Code: [Select]
#!/bin/sh
# Purpose=To replace "_" in file names with spaces

for i in "$1"; do mv "$i" "`echo $i | tr '_' ' '`"; done

1) I saved the script as Remove_those_damn_lines.sh;
2) I made it executable;
3) I copied it as root to /usr/local/bin
        (You can also, as old-polack suggested, create a ~/bin folder and copy it there; I assume you also need to put it in you path)

4) I created a .desktop file in ~/kde/share/apps/konqueror/servicemenus and pasted the following:

Code: [Select]
[Desktop Entry]
Actions=Remove_those_damn_lines
ServiceTypes=all/allfiles

[Desktop Action RemoverGuiones]
Name=Remove those damn ugly lines
Icon=borderbottom
Exec=Remove_those_damn_lines %U

It gives you a service menu in konqueror to replace the "_" with spaces only for the files that you have selected.

If you like or need the "_", you can substitute
    for i in "$1"; do mv "$i" "`echo $i | tr '_' ' '`"; done
with
    for i in "$1"; do mv "$i" "`echo $i | tr ' ' '_'`"; done

Actually, you can substitute whatever you want; if you have a thing for the letter "a", you can change it to "j", etc.

Hope it helps someone.