Remove regularly repeated lines

How can i delete some regular repeated lines in a file?
example:
in_file

EDGE 1 2 12
EDGE 2 3 23
EDGE 3 4 34
EDGE 5 6 56
EDGE 6 7 67
EDGE 7 8 78
EDGE 9 10 910
EDGE 10 11 1011
EDGE 11 12 1112
EDGE 13 14 1314
EDGE 14 15 1415
EDGE 15 16 1516
EDGE 17 18 1718
EDGE 18 19 1819
EDGE 19 20 1920
EDGE 21 22 2122
EDGE 22 23 2223
EDGE 23 24 2324
EDGE 25 26 2526
...

i want remove each 3 lines together after 5 line passed, so the result of that action in this example would be :

EDGE 1 2 12
EDGE 2 3 23
EDGE 3 4 34
EDGE 5 6 56
EDGE 6 7 67

EDGE 11 12 1112
EDGE 13 14 1314
EDGE 14 15 1415
EDGE 15 16 1516
EDGE 17 18 1718

EDGE 22 23 2223
EDGE 23 24 2324
EDGE 25 26 2526
...

Not clear. Your output's first and third block have four lines, and I can't see a pattern on which to decide which lines to keep and which to remove. Pls be more specific.

Your requirement doesn't seem to match the sample data:

EDGE 1 2 12 
EDGE 2 3 23 
EDGE 3 4 34 
EDGE 5 6 56

These are four, not five lines.

try:

awk '{if (++c % 6 && !d) {e=d=0; print } else {if (++e % 4) {d=1; c=0} else {print "\n"$0; d=e=0}}}' input
1 Like
awk 'BEGIN{L=1}{if(!(L>5&&L<9)) print; L++; if(L==9) {print " "; L=1;} } ' filename
1 Like

roughly:

awk '
# c print line counter
# d skip line flag
# e skipped line counter
{if (++c % 6 && !d) {    # mod test for c line count (not 0) and skip line flag set to 0
  e=d=0; print           # print line reset e set d to 0
} else {
  if (++e % 4) {         # mod test for skipped line counter (not 0)
    d=1; c=0             # set skip line to 1, reset print line counter
  } else {
    print "\n"$0; d=e=0  # print first line of block with separator, reset print line counter,
                         # and set skip line to 0
  }
}
}' input
1 Like

Unless I'm missing something, the above scripts seem overly complex. Try:

awk 'NR % 8 == 1 && NR > 1 {
        # Print an empty line separator between sets of 8 input lines.
        printf("\n")
}       
(NR - 1) % 8 < 5 # Print the 1st 5 lines in each set of 8 input lines. 
' in_file
2 Likes
sed -n 'p;n;p;n;p;n;p;n;p;x;p;x;n;n;n'