Bill Jonas on Tue, 20 Nov 2001 19:30:16 +0100 |
On Tue, Nov 20, 2001 at 12:44:47PM -0500, Jason Wertz wrote: > am I missing a command line arg or is my use of the command wrong? It's actually a shell issue, not sed. The way that redirection works is that when you enter the command, the specified file is opened for writing right away, including truncation is you specify > instead of >>. The command does not complete first. So basically, if you do something like 'sed s/class=\"bodytext\"//g computing.php > computing.php', computing.php is truncated and opened for writing, then the sed command is run. Since the file now has no contents, the sed command will exit, and you're left with a zero-length file. The shell doesn't know how big the output is going to be. Consider the extreme case. Imagine if you ran that command on a 1.5GB file; the shell would be trying to buffer all that data in memory before writing it to disk. In a book I read (it might have been _Programming in the UNIX Environment_), a shell-script solution was presented to allow this sort of thing without having to make a temporary file either before or after. I don't have the book in front of me (it was borrowed), but I can try recall it if anyone's interested. -- Bill Jonas * bill@billjonas.com * http://www.billjonas.com/ Developer/SysAdmin for hire! See http://www.billjonas.com/resume.html Attachment:
pgpGYKM9OiOQW.pgp
|
|