On Sat, 6 Dec 1997 16:25:47 -0700 (MST), William McClatchie
<wmcclatc(_at_)primenet(_dot_)com> wrote:
| ( sed -n /$REMOVE/d .address > $HOME/temp_file mv tempfile .address) ;
You might also find that doing this with either a perl of sh script
will work more reliably. I've found that on Netcom's semi-screwed
up mail system it is best to do such things in scripts. It also
makes testing the things a bit easier. :-)
#!/bin/sh
# This also leaves temp_file around as a backup
mv .address $HOME/temp_file
grep -v $SAFEREMOVE $HOME/temp_file > .address
You should still double-quote $SAFEREMOVE, and probably move the
locking into the script itself (see the other thread about lockfile.)
And I'd still prefer to have the temp file in /tmp or /usr/tmp rather
than in my home directory. YMMV.
#!/bin/sh
# gred -- like grep, but remove matching lines
# syntax: gred regex file
# locks file while gredding using dotlocking
case "$#" in
2) ;;
*) echo "Syntax: gred regex file" >&2 ; exit 1 ;;
esac
LOCK="$2.lock"
TMP=/tmp/$$.temp
if lockfile "$LOCK"; then
mv "$2" "$TMP"
grep -v "$1" "$TMP" >"$2"
rm -f "$LOCK"
fi
The name "gred" is rather obscure if you don't know what "grep" stands
for. Anyway, this is also really too specialized a script to get such
a general-sounding name.
Incidentally, I timed this against a Perl one-liner on my
/usr/dict/words (which is rather small, though; some 25,000 lines) and
found the shell version to be quicker, even with the locking.
A good citizen would take care to remove the temp files when done,
but since Wotan thought it would be valuable to keep them around for
backup, I left implementing that as an exercise. (Hint: they should be
cleaned up even if the script is interrupted with ctrl-C.)
Smoking is one of the leading causes of statistics.
-- Fletcher Knebel
:-)
/* era */
--
Paparazzi of the Net: No matter what you do to protect your privacy,
they'll hunt you down and spam you. <http://www.iki.fi/~era/spam/>