3 ms·
If you wanted to grab 10 lines from /var/log/messages, starting at the first line that has "pjungwlr" in it, you could: $ less /var/log/msgs /pjungwlr^M
by bch 12y ago
If you wanted to grab 10 lines from /var/log/messages, starting at the first line that has "pjungwlr" in it, you could:
$ less /var/log/msgs
/pjungwlr^M
^G (note line informational line numbers)
v (launch vi)
[double check your line #s, etc]
:d1,. (delete from 1st line, to current line)
10j (go down 10 lines)
:d,$ (delete to EOF)
:w my_newfile
:q
- technofiend 12y agoThis is such a common problem there's a stackoverflow article on it. http://stackoverflow.com/questions/17908555/printing-with-sed-or-awk-a-line-following-a-matching-pattern http://stackoverflow.com/questions/17908555/printing-with-se... (Actually, there's probably more than one despite their really good duplication grooming, but this was the first hit.)
- pjungwir 12y ago`v` was the missing key for me. Looks like it even preserves my position in the file. Thanks!