[SWLUG] Find And Replace.

Geraint Edwards gedge-lists-swlug at yadn.org
Thu Jan 7 15:22:50 UTC 2010


Ysgrifennodd Andrew Jenkins <adjenkins at gmail.com> said
		(on Thu, Jan 07, 2010 at 03:15:16PM +0000):
> Ah, now I'm getting somewhere. That 'sort-of' worked Geraint.
> It works fine as long as there are no 'spaces' in the filename;

Hmm, looks like the loop is catching the spaces (at $src, so to speak).
Force $src to be a whole line (i.e. filename with spaces) with this version:

#!/bin/bash
find Music -type f -name \*.mp3 | while read src; 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

-- 
Geraint A. Edwards (aka "Gedge")
gedge at yadn.org



More information about the Swlug mailing list