News for hackers. Stuff that matters.
Re:What's the one Linux command you wish you knew years ago? by steve-howard on Sunday November 20, 2011 @03:14AM (#3257601)
sed -i does the same thing as perl -pi. Though I've not encountered a system that doesn't have both.
Re:What's the one Linux command you wish you knew years ago? by Someone on Sunday November 20, 2011 @03:34AM (#3257637)
sed's regular expressions are different from those perl uses (even when using the (¿gnu sed?) flag that tells sed to use extended regular expressions). Especially if you "live in perl", that can be a problem.
Re:What's the one Linux command you wish you knew years ago? by michaelcampbell on Sunday November 20, 2011 @11:43AM (#3258424)
Does sed allow in-place file replacement, or do you need to redirect to a different file then cp/mv it over the original? I haven't used it in many years, but sed didn't used to allow this.
Re:What's the one Linux command you wish you knew years ago? by derwiki on Sunday November 20, 2011 @11:58AM (#3258463)
sed -i 's/old/new/g' file
Re:What's the one Linux command you wish you knew years ago? by 1010010101 on Sunday November 20, 2011 @04:42PM (#3259095)
Note: "cmds" is one or more s commands. For other commands, if it's a big file, I will just pipe through less (still no temp file) and then save the buffer (to overwrite the original file), instead of using this hack.

A hack for in-place editing, for old school sed (no -i):

sedi(){ case $# in 0) echo usage: sedi cmds file;; 2) sed -an ' '"$1"'; H; $!d; g; w '"$2"'' $2;; esac; }