How do you use sed to edit a file?
I need to change one word in over a thousand pages of HTML. I think sed is the only way to do this, but I've never used sed before.
After reading the documentation, I see that it is pretty easy to alter files to standard output, in other words, the screen. But I don't want to do just alter text to the screen, I want to alter the original file, else I am not doing any Stream EDiting as near as I can tell. None of the documentation explains how to take a file, apply sed to alter that file. How do you do this? I'm pretty clear on the basics, Code:
[myuser@myhost dir]#sed s/changethis/tothis/ /mydir/myfile |
Code:
sed s/changethis/tothis/ /mydir/myfile > /tmp/newfile Code:
-i[SUFFIX], --in-place[=SUFFIX] |
Thanks AlucardZero, -i did the trick. Perl from the command line has a similar feature. My "Linux in a Nutshell" is a ten year old edition. Time to upgrade.
Why would I want to use the redirection and mv command? Did you imagine I might have a really old Linux distribution? |
It's just another way to do things.
|
All times are GMT -5. The time now is 02:23 AM. |