Quote:
Originally Posted by another 1
i couldn't use their code until that i noticed the -i in your command. i thing it is about saving the output in the same file. thnks
|
Yes, it is. Not every version of sed has the -i option (for example, the one on the Solaris servers we have at work), so it won't always be mentioned in how-tos. A similar effect to using -i can be obtained by:
Code:
sed '/expression/ s/^/#/' file > temp_file && \
mv temp_file file
... which writes the output of sed to a temporary file,then if (and only if) sed completes without errors, overwrites the original with the temporary file. One trap to watch out for is that you can't simply redirect the output to the original file:
Code:
sed '/expression/ s/^/#/ file > file # Don't do this!
... as the redirect operator immediately truncates the file
before sed gets a chance to read it.(
).