问题
I have a text file with a lot of number combinations. It looks like this:
1 2 3 4 5 6
1 2 3 4 5 7
1 2 3 4 5 8
1 2 3 4 5 9
1 2 3 4 5 10
Every line has 6 numbers with a space between each number. Numbers go from 1 to 37.
I need an AWK command to remove any line with 2 or 3 consecutive pairs.
For example:
1 2 6 9 13 14
4 5 18 19 25 26
Thanks!
回答1:
awk '{pairs = 0; for (i = 1; i < NF; i++) if ($i + 1 == $(i + 1)) pairs++; if (pairs != 2 && pairs != 3) print}' input_file
来源:https://stackoverflow.com/questions/57806614/removing-lines-with-consecutive-pairs