Removing lines with consecutive pairs

帅比萌擦擦* 提交于 2020-01-05 03:46:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!