Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grep tail and head wrong result

I want to show the 3 first lines and the 2 last lines that contain a word. I tried a grep command but it's not showing what I want.

grep -w it /usr/include/stdio.h | head -3 | tail -2

It only display the 2nd and 3nd lines that contain "it" in it.

like image 802
avanabana Avatar asked Feb 25 '26 17:02

avanabana


1 Answers

You can simply append the results of head and tail :

{ head -3 ; tail -2 ;} < /usr/include/stdio.h
like image 50
Mahmoud Avatar answered Feb 27 '26 07:02

Mahmoud



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!