[SWLUG] Find And Replace.

Geraint Edwards gedge-lists-swlug at yadn.org
Thu Jan 7 14:52:49 UTC 2010


Ysgrifennodd Andrew Jenkins <adjenkins at gmail.com> said
		(on Thu, Jan 07, 2010 at 02:18:24PM +0000):
> I have a few thousand MP3 files which are all under a general "Music" 
> directory
> but all within separate directories under that.  At the moment they have 
> just a
> '-' (dash) between the artist name and the track name. I would like them 
> to have
> ' - ' (space, dash, space) instead.

This should work for file that don't have double-quotes in the names.

#!/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/-/ - }
	#	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