[Gllug] error in bash script to rename files in a directory
Tethys
tet at accucard.com
Tue Dec 31 10:17:07 UTC 2002
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?
for i in *
do
sed 's/php3/php/g' "$i" > "$i.$$"
[ -s "$i.$$" ] && mv "$i.$$" "$i"
done
Tet
--
Gllug mailing list - Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug
More information about the GLLUG
mailing list