4 ms·
Still use ed commands but mostly in vi command line mode. For me the most useful feature is the ability it has to remember the contents of regular expression m
by dave333 4y ago
Still use ed commands but mostly in vi command line mode.
For me the most useful feature is the ability it has to remember the contents of regular expression matches inside \( ... \) and when you combine this with the g global edit command you can do complex manipulations in a similar way on every line in a file with a single ed line.
So
g/\(regex1\)whatever\(regex2\)/s//\2something\1/
switches whatever text matches regex1 and whatever matches regex2 and changes the intermediate text also.
It's a lot to type but quite easy once you have done it a few times to write a single edit that transforms your file exactly the way you want in one go or nearly so.
However dealing with columnar data it's probably better to use something like awk.