[ale] sed
Danny Cox
danscox at mindspring.com
Fri May 18 10:17:45 EDT 2007
And another old fart weighs in:
On Thu, 2007-05-17 at 21:51 -0400, David Tomaschik wrote:
> Jamey Owens wrote:
> > One note of caution. It can be pretty dangerous to try and use the same
> > file for input and output. Lots of shells will leave you with a totally
> > empty file using the previous sed command with input & output being equal.
> >
> >
> Are there any shells capable of handling that structure in the way one
> would expect? (i.e., acting on the single file without destroying or
> requiring a temporary file to be moved around)
In "The UNIX Programming Environment", they build up a shell script
named "overwrite", which will do what you want. The syntax is something
like this:
overwrite cmd file
and you probably had to quote the command due to redirects, and the
like. To use the current thread's example, it would look something like
this:
overwrite 'sed "s/abc/xyz/g" file' file
and it would do the right thing.
Undoubtedly, there's a replacement script already included, or some
neat bash syntax for doing this sort of thing these days. ;-)
--
kernel, n.: A part of an operating system that preserves the
medieval traditions of sorcery and black art.
Danny
More information about the Ale
mailing list