This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

4 Answers
4

p is a print flag - p means print when p is true, as the default action is print when none is provided. In awk, variables start out empty, which evaluates to false in Boolean contexts. Every time a > ... line is reached, toggle the p flag.

It's similar logic, except since n is not 2 we have to use a counter instead of a Boolean flag. Here, skip counts how many more > ... lines to skip before we start printing again. I'm using skip == n - 1 as the print flag as a bit of a short cut.

sorry, as I am new to awk, Could you please explain me. In my question I asked to skip every 2nd ">", what I can do If want to skip every 200 occuring ">"
–
jackOct 12 '12 at 16:03

+1 for nice and simple in your first solution. The second command does not work though, it prints the 1st line and then each n+1th line after that. I.e. for n=4, it will print the 1st,6th,11th,16th etc instead of 1st,5th,9th,13th etc.
–
terdon♦Oct 12 '12 at 16:28

@terdon You are right, I had an off-by-1 bug. I feel slightly embarrassed lol. :P
–
jw013Oct 12 '12 at 16:33

This increments the variable k every time a line starts with > and prints the lines if k modulo 10 is 0. So, if you want to print every 2nd line, change k%10==0 to k%2==0, for every 200th line change it to k%200==0 etc.