如何在两种模式之间打印与精确单词匹配的行?
我正在使用:
echo "CMDM." | awk 'string one ttt/{flag=1;next}/string two ttt/{flag=0}flag' <file>
所以,我需要打印包含单词&#34; CMDM的行。&#34;字符串之间 将一个ttt和一个字符串两个ttt重复,直到EOF。
答案 0 :(得分:0)
你的例子毫无意义。你回复awk的东西,然后awk读取一个文件,忽略你回应的东西。
无论如何,您所寻找的似乎是:
$ awk '/string one ttt/{flag=1;next}/string two ttt/{flag=0}flag && /CMDM/' inputfile
如果你需要在awk中组合管道和文件,你可以这样做:
$ echo "something" |awk '{print}' file1 -
# the dash in the end means read from stdin.
# awk will treat stdin as a second file which will be processed after the first file.