我正在尝试找到一个字符串模式,该字符串模式由结论一词组成,后跟字段$ 2的值,字段$ 3来自字段$ 5中的相同记录.
例如,my_file.txt用"|"分隔:
1|substance1|substance2|red|CONCLUSIONS: the effect of SUBSTANCE1 and SUBSTANCE2 in humans...|
2|substance3|substance4|red|Conclusions: Substance4 is not harmful...|
3|substance5|substance6|red|Substance5 interacts with substance6...|
Run Code Online (Sandbox Code Playgroud)
所以在这个例子中我只想要打印第一条记录,因为它有"结论"字样,后面substance1跟着substance2.
这是我正在尝试但它不起作用:
awk 'BEGIN{FS="|";IGNORECASE=1}{if ($5 ~ /CONCLUSIONS.*$2.*$3/) {print $0}}' my_file.txt
Run Code Online (Sandbox Code Playgroud)
任何帮助深表感谢