[Gllug] error in bash script to rename files in a directory
Stig Brautaset
gllug at brautaset.org
Tue Dec 31 12:34:21 UTC 2002
On Dec 31 2002, Tethys wrote:
>
> Stig Brautaset writes:
>
> >> $ perl -p -i.bak -e 's/php3/php/g' *
> >
> >Or without perl:
> >
> >for i in *; ex $i <<EOF
> >,s/php3/php/g
> >wp
> >EOF
> >done
>
> True, but ex is designed as an interactive editor, and while you *can*
> kludge it to run non-interactively like this, why not just use sed,
> which was desgined from the start for non-interactive use?
Because I wanted to be different :)
> for i in *
> do
> sed 's/php3/php/g' "$i" > "$i.$$"
> [ -s "$i.$$" ] && mv "$i.$$" "$i"
> done
You have to admit that this isn't exactly pretty. I've found myself many
times wanting a 'same file' flag to sed. That would ease these cases a
bit, but I'm not sure it's a good idea for other reasons.
Stig
--
brautaset.org
--
Gllug mailing list - Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug
More information about the GLLUG
mailing list