Reputation: 182
I want to skip two lines and delete two lines till the end of file
if my file contains
111
222
333
444
555
666
777
888
999
1010
1111
I want to modify it to look like
111
222
555
666
999
1010
Upvotes: 1
Views: 174
Reputation: 41460
Using awk
awk 'NR%4==1 || NR%4==2' file
111
222
555
666
999
1010
NR%4==1
prints line 1,5,9 etc
NR%4==2
prints line 2,6,10 etc
So it gives line 1,2 5,6 9,19 etc
Other version:
awk 'NR%4~/^[12]$/' #JS웃
awk '(NR-1)%4<2' #Ed Morton
Upvotes: 6
Reputation: 2160
A vim only solution:
:%norm Jj2dd Aaaaa
then
:%s/aaaa /\r/g
You need to split the first line manually(have n), rest everything is in place.
Upvotes: 0
Reputation: 123608
Using sed
:
sed -n 'p;n;p;n;n' inputfile
For your given input, it'd produce:
111
222
555
666
999
1010
Using GNU sed:
sed -n '1~4p;2~4p' inputfile
For fun, one could also use perl
:
perl -ne 'print if grep($_==$.%4,(1,2))' inputfile
Upvotes: 4