[plug] grep task?
Cameron Patrick
cameron at patrick.wattle.id.au
Sat Nov 22 14:21:46 WST 2003
On Sat, Nov 22, 2003 at 02:16:43PM +0800, Cameron Patrick wrote:
| On Sat, Nov 22, 2003 at 02:02:57PM +0800, John Knight wrote:
|
| | Are there any greppers who could could tell me how to get a certain task
| | out of the way? I've got to go through several directories of html pages
| | and change an email address in them.
| |
| | I'd be wanting the script to:
| | 1. search through the files for "anarchist_tomato at hotmail.com"
| | 2. if found, replace with "entombednerds at yahoo.co.uk"
| | 3. report the name of the file that's just been changed.
| |
| | Is that possible?
|
| Not using grep, but sed will do it:
Oh, some more hackery will be required for part 3. Perhaps something
like:
for file in *.html; do
sed 's/anarchist at blah/entombednerds at blah/g' <${file} >${file}.new || exit 1
if cmp -s ${file} ${file}.new; then
# file hasn't changed
rm ${file}.new
else
# file has changed
echo "changing ${file}"
mv ${file} ${file}.old
mv ${file}.new ${file}
fi
done
Bash scripting is handy for this kind of thing :-) The above is
completely untested, BTW.
Cameron.
_______________________________________________
plug mailing list
plug at plug.linux.org.au
http://mail.plug.linux.org.au/cgi-bin/mailman/listinfo/plug
More information about the plug
mailing list