![根据单词组合模式过滤行](https://linux22.com/image/993255/%E6%A0%B9%E6%8D%AE%E5%8D%95%E8%AF%8D%E7%BB%84%E5%90%88%E6%A8%A1%E5%BC%8F%E8%BF%87%E6%BB%A4%E8%A1%8C.png)
我的文本文件如下所示:
city=london&language=en&x=12345&y=6789&z=7
sometext?z=7
city=dublin&language=en&x=12345&y=6789&z=7
city=madrid&language=en&x=12345&y=6789&z=7
sometext?y
sometext?x
我需要根据条件过滤文本 - 如果某行包含:
city, language, x, y, z anywhere in the line
留下这行字。
过滤数据后的输出将是:
city=london&language=en&x=12345&y=6789&z=7
city=dublin&language=en&x=12345&y=6789&z=7
city=madrid&language=en&x=12345&y=6789&z=7
最简单的方法是什么?
答案1
您可以直接在逻辑上组合正则表达式测试,awk
例如
$ awk '/city/ && /language/ && /x/ && /y/ && /z/' file.txt
city=london&language=en&x=12345&y=6789&z=7
city=dublin&language=en&x=12345&y=6789&z=7
city=madrid&language=en&x=12345&y=6789&z=7