[SWLUG] Find And Replace.

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


Geraint Edwards wrote:
> 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
>
>   
Cheers Guys, I'm not very good with reg-ex but I'll go away and
try to make some sense of your answers and see if I can chop and
change and get it working.

Andy.

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





More information about the Swlug mailing list