我的文本文件如下所示:
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