Here’s a useful feature of sed, the linux stream editor, that I didn’t know about before.
My problem was that within a file, I wanted to only operate on lines that contained a certain expression – but leaving that expression intact and instead changing another expression on that line.
The standard sed command for replacing one expression with another is
which replaces ‘foo’ with ‘bar’ on every line where ‘foo’ is found. But what if you only want to carry out that replacement on lines that contain the word ‘gnu’? The solution is this…