Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!spool.mu.edu!uunet!mcsun!ukc!pyrltd!root44!gwc From: gwc@root.co.uk (Geoff Clare) Newsgroups: comp.unix.shell Subject: Re: cat, pipes, and filters Message-ID: <2730@root44.co.uk> Date: 4 Jun 91 13:03:32 GMT Article-I.D.: root44.2730 References: <1991May31.165446.1530@progress.com> <10918@chorus.fr> Organization: UniSoft Ltd., London, England Lines: 25 In <10918@chorus.fr> bp@chorus.fr (Bruno Pillard) writes: >What about: > ( /bin/rm $FILE ; sed s/"$ENTRY"/"$NEWENTRY"/ > $FILE ) < $FILE >I understand that this may look harmful at first glance because of the >/bin/rm of your precious file but it works perfectly for me under sh >and (t)csh. >Is there any problem using that construction ? Yes! If any errors occur you lose your data. Slightly better would be: ( /bin/rm $FILE && sed s/"$ENTRY"/"$NEWENTRY"/ > $FILE ) < $FILE which would not truncate the file if the "rm" fails, but this still loses your data if the disk is full. It's much safer to: sed s/"$ENTRY"/"$NEWENTRY"/ < $FILE > $TMPFILE && mv $TMPFILE $FILE -- Geoff Clare (Dumb American mailers: ...!uunet!root.co.uk!gwc) UniSoft Limited, London, England. Tel: +44 71 729 3773 Fax: +44 71 729 3273