[YLUG] How do to substition in a file with sed or similar

Robert Hulme rob at robhulme.com
Fri Oct 27 11:48:05 BST 2006


Hi list,

I know I can:
sed s/foo/bar/ myfile

which dumps to stdout

How I do the substition on the file 'in place'?

sed s/foo/bar/ myfile > myfile

Results in a zero length file (which I'd kinda expect from the stream editor).

Do I need to use a temporary file or is there some kind of buffer I could use:
sed s/foo/bar/ myfile | streambuffer > myfile

Or is there a magic switch or should I be using something other than sed?

Thanks muchly,
-Rob

-- 
------------------------------------------------------
"By all means let's be open-minded, but not so open-minded that our
brains drop out." - Richard Dawkins

"It is far better to grasp the universe as it really is than to
persist in delusion, however satisfying and reassuring." - Carl Sagan

http://www.robhulme.com/
http://robhu.livejournal.com/



More information about the York mailing list