You're replying to a comment by Vadim Bogulean.

Vadim Bogulean Permalink
March 02, 2013, 09:15

Hi and thanks for your tips.
I was actually looking a way to print certain number of lines after searching a line in a file.

Based on the tips from 'Print lines using patters' I could elaborate one for my needs. Thought you could add it as well for others.

awk "{cnt-=1;if(cnt<=0)p=0;}/$1/{p=1;cnt=$2}p" $3

where $1, $2 $3 to be replaced with :
$1 - Your search pattern,
$2 - Number of lines to display (including searched pattern)
$3 - Your input file

i.e
$ awk "{cnt-=1;if(cnt<=0)p=0;}/Error:/{p=1;cnt=2}p" file

file content:
Error:
Error # 1
Warning:
Warning # 2
Error:
Error # 3

Result would be:
Error:
Error # 1
Error:
Error # 3

Reply To This Comment

(why do I need your e-mail?)

(Your twitter name, if you have one. (I'm @pkrumins, btw.))

Type the word "browser_100": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.