Considering this file:
1 2 3 4 5 I can extract the last 3 lines with this sed one-liner:
$ /bin/sed input.txt -e ':a;$q;N;4,$D;ba' But I would also like to add some characters (# ) in front of each line, so that the output will be like so:
# 3 # 4 # 5 How can I modify the one-liner to do that? I mean, without adding another sed invocation (with | /bin/sed -e 's/^/# /').
I would prefer to use sed only for the same reasons of the original question, i.e. I have a system with limited binaries available.
sedinvocation? I mean any issue with usingsedtwo times?tacavailable? If so, reverse the file, extract the first n lines and modify them, then reverse the result.