4 ms·
You can get the same behaviour with sed without "programmability": $ sed -n '/^func Test/,/^}/p' file Which means: match 'func Test' at the beginning of a l
by dbolgheroni 8y ago
You can get the same behaviour with sed without "programmability":
$ sed -n '/^func Test/,/^}/p' file
Which means: match 'func Test' at the beginning of a line and print (p command at the end) until you find a line beginnning with '}'.
This is because the print command (p) accepts 2 addresses to delimit a range. I used regexes as addresses but, for instance, can use line numbers also:
$ sed -n '10,20p' file
This prints file's line from 10 to 20.
By default, sed prints the pattern space (modifications to each line) at the end of the script. The -n I used is to avoid that.
- akavel 8y agoHah, lol, thanks, Today I Learnt ;) Will try using this next time, probably. That said, there's one extra advantage with the awk script, that by rearranging the expressions appropriately, I can choose whether to include or exclude the the first and last line in the output (i.e. 'FIRST; p; LAST' vs. 'FIRST; LAST; p' or 'p; FIRST; LAST', etc.) Is this also possible with sed? :)