You're viewing a comment by Peteris Krumins and its responses.

February 12, 2009, 01:02

Yogesh, I have three answers for you:

awk 'f;{f=/foo/}'
awk 'c&&!--c;/foo/{c=1}'
awk '/foo/{_[NR+1]}NR in _' 

And my friends from #awk channel suggested a bunch of variations:

a) Print all records from some pattern:

     awk '/pattern/{f=1}f' file

b) Print all records after some pattern:

     awk 'f;/pattern/{f=1}' file

c) Print the Nth record after some pattern:

     awk 'c&&!--c;/pattern/{c=N}' file

d) Print every record except the Nth record after some pattern:

     awk 'c&&!--c{next}/pattern/{c=N}' file

e) Print the N records after some pattern:

     awk 'c&&c--;/pattern/{c=N}' file

f) Print every record except the N records after some pattern:

     awk 'c&&c--{next}/pattern/{c=N}' file

Reply To This Comment

(why do I need your e-mail?)

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

Type the first letter of your name: (just to make sure you're a human)

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