How to print lines number 15 and 25 out of each 50 lines?
awk 'NR % 50 == 15 || NR % 50 == 25'
would be the obvious portable way.
Note a GNU sed
alternative:
sed '15~50b;25~50b;d'
With any sed
, you can always do:
sed -n 'n;n;n;n;n;n;n;n;n;n;n;n;n;n;p;n;n;n;n;n;n;n;n;n;n;p;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n'
(get next line 14 times, print, next line 10 times, print, next line 25 times, back to the next cycle (which grabs the missing extra line to make 50)).
this is a job for awk
awk '(NR%50==15) || (NR%50==25)' inputfile
edit: I was mislead by sed instruction in OP.
With perl
1) Similar to the awk
solution, $.
variable stores line number
$ seq 135 | perl -ne 'print if $.%50==15 || $.%50==25'
15
25
65
75
115
125
2) Check against list of line numbers, easier to extend
$ seq 135 | perl -ne 'print if grep {$_==$.%50} (15,25)'
15
25
65
75
115
125
$ seq 135 | perl -ne 'print if grep {$_==$.%50} (15,25,32)'
15
25
32
65
75
82
115
125
132