Answer the question
In order to leave comments, you need to log in
How to get the first and last lines that matches a given word in bash?
There is a file log. How to get the string of first and last occurrence for a given word?
Answer the question
In order to leave comments, you need to log in
Offhand
$ cat 1.txt
1 line
2 line
3 bar
4 line
5 line
6 line
7 foo
8 line
9 line
$ grep line 1.txt | sed -n '1p;$p' -
1 line
9 line
grep line 1.txt | sed '1!{$!d}'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question