[SWLUG] Find And Replace.
Geraint Edwards
gedge-lists-swlug at yadn.org
Thu Jan 7 14:59:38 UTC 2010
Ysgrifennodd Geraint Edwards <gedge-lists-swlug at yadn.org> said
(on Thu, Jan 07, 2010 at 02:52:49PM +0000):
> tgt_f=${tgt/-/ - }
Oops, try this instead:
#!/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).
--
Geraint A. Edwards (aka "Gedge")
gedge at yadn.org
More information about the Swlug
mailing list