[SWLUG] Find And Replace.

Andrew Jenkins adjenkins at gmail.com
Thu Jan 7 15:15:16 UTC 2010


Geraint Edwards wrote:
> #!/bin/bash
> for src in $( find Music -type f -name \*.mp3 ); do
> 	#	tgt_f = src filename (remove path)
> 	tgt_f=${src##*/}
> 	#	put spaces around (first) dash in tgt_f
> 	tgt_f=${tgt_f/-/ - }
> 	#	rename file, keeping in same directory, i.e. in ${src%/*} 
> 	mv -i "$src" "${src%/*}/$tgt_f"
> done
>
>
> Note, that I've quoted "$src" (etc.) because they will likely have special
> characters in them, like spaces, and need to be treated as one argument
> (not multiple space-separated arguments, as seen by the errors in your
> later post).
>
>   
Ah, now I'm getting somewhere. That 'sort-of' worked Geraint.
It works fine as long as there are no 'spaces' in the filename;
Aerosmith-Amazing.mp3 worked OK but
Aerosmith-Boogie Man.mp3 threw out with a message about
it not being a directory (similar to what I had at first).

Andy.

-- 
Microsoft have broken Volkswagen's world record: Volkswagen only made 
22 million bugs!





More information about the Swlug mailing list