Message-ID: <8D53104ECD0CD211AF4000A0C9D60AE301545D82@probe-2.acclaim-euro.net> From: Shawn Hargreaves To: djgpp AT delorie DOT com Subject: Re: Global file edit? Date: Tue, 3 Aug 1999 09:50:09 +0100 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.0.1460.8) Content-Type: text/plain Reply-To: djgpp AT delorie DOT com Dave Scott writes: > Is there a simple utility available to do something like this :- > > edit A decent programming editor should have builtin support for search/replace across multiple files. But if you need to do this in a standalone form, try something like: ---- cut here, globalreplace.sh ---- #! /bin/sh if [ $# -lt 2 ]; then echo "Usage: globalreplace oldstring newstring files" 1>&2 exit 1 fi oldstring=$1; shift newstring=$1; shift echo "Changing $oldstring to $newstring" for file in $*; do if [ -f $file ]; then echo "Editing $file" mv $file tmpfile sed -e "s/$oldstring/$newstring/g" tmpfile > $file touch -r tmpfile $file rm tmpfile else echo "Error: $file not found" fi done Shawn Hargreaves.