[Klug-general] Space to underscore?

sharon kimble boudiccas at talktalk.net
Wed May 16 02:39:41 UTC 2012


On Tuesday 15 May 2012 13:44:40 David Halliday wrote:
> Hi,
> 
> You should be able to modify this:
> http://www.sharons.org.uk/taste/archives/2012/05/index.html#e2012-05-01T00_
> 50_12.txt
> 
> 
>    - If you want to rename directories also, then just remove the: -type f
>    - If you want to do ALL files then remove the sections relating to
> name: -name
>    '*.MP3'
>    - If you want to go based on a name filter, you can actualy keep the
>    command more simple using case insensitive name matching: -iname "*.mp3"
>    - Rather than the more convoluted: \( -name '*.mp3' -o -name '*.MP3' \)
> 
> You should end up with something like this:
> 
> #!/bin/bash
> 
> find $1 -name "* *" |
> while IFS= read -r NAME;
> do
>   DEST=`echo "$NAME" | tr ' ' '_'`
>   mv -v "${NAME}" "${DEST}"
> done
> Tested by adding that to a script: test.sh

Thanks for this, I called mine 'spaces2.sh' and saved it in my cron directory, 
then did chomd 755 spaces2.sh and then ran it as ./spaces2.sh 
/home/boztu/Music/ . At first I though tit wasn't really doing anything, so I 
killed it and then looked at the titles in /music/ and saw the underscores so 
I restarted it and let it finish. And it worked like a dream, thank you very 
much for it.

Now to try out datapacker, and if it works okay then I'm willing to do a 5-
minute talk on it at some stage in the future. 

Thanks again
Sharon.
> 
> Sample usage:
> [user at host]$ mkdir test
> [user at host]$ touch test/"file one.txt"
> [user at host]$ touch test/"file two.txt"
> [user at host]$ touch test/"filethree.txt"
> [user at host]$ ls test/
> file one.txt  filethree.txt  file two.txt
> [user at host]$ ./test.sh test/
> `test/file one.txt' -> `test/file_one.txt'
> `test/file two.txt' -> `test/file_two.txt'
> [user at host]$ ls test/
> file_one.txt  filethree.txt  file_two.txt
> 
> 
> The -name "* *" searches for anything with a name containing a space (no
> pint in modifying files without spaces). You can change it to "* *.mp3" for
> mp3 files only. Or use -iname for case insensitive searches.
> 
> On 14 May 2012 23:04, sharon kimble <boudiccas at talktalk.net> wrote:
> > This is probably quite easy if you already know the answer, but I'm not
> > very
> > good at scripting.What I'm looking for is a script to go through my
> > /home/foo/Music directory converting all the album titles with spaces in
> > to convert them to underscores.
> > 
> > Can anyone help please?
> > 
> > Thanks
> > Sharon.
> > --
-- 
A taste of linux = http://www.sharons.org.uk/taste/index.html
efever = http://www.efever.blogspot.com/
efever = http://sharon04.livejournal.com/
Debian 6,0.5, Gnome 1:2.30+7, LibreOffice 3.4.6
Registered Linux user 334501 



More information about the Kent mailing list