Date: Fri, 31 May 2002 19:51:21 -0400 From: Andrew J Caines <A.J.Caines@halplant.com> To: freebsd-questions@freebsd.org Subject: Re: Why does 'sed' delete my input file? Message-ID: <20020531235121.GK32486@hal9000.halplant.com> In-Reply-To: <20020531130029.B28925@dogma.freebsd-uk.eu.org> References: <20020531130029.B28925@dogma.freebsd-uk.eu.org>
next in thread | previous in thread | raw e-mail | index | archive | help
There have been quite a few suggestions how best to do this, most of which should work, however I suggest the most general functional solution is as follows: # for file in file1 file2 file3 ... do cp $file $file.x && sed 's/re/pattern/f' $file.x > $file && rm $file.x done This can be trivially set up as a function. This has several advantages: you keep the file mode and CTIME of $file, which doesn't necessarily happen with mv; you have a copy of the original if the sed fails; it scales to multiple files; it can be made parallel easily with job control and it works with full (or partly qualified) paths (unlike when you use /tmp or similar). -Andrew- -- _______________________________________________________________________ | -Andrew J. Caines- Unix Systems Engineer A.J.Caines@halplant.com | | "They that can give up essential liberty to obtain a little temporary | | safety deserve neither liberty nor safety" - Benjamin Franklin, 1759 | To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020531235121.GK32486>