如何使用Word边界awk中不使用匹配()函数? [英] How to use word boundaries in awk without using match() function?
本文介绍了如何使用Word边界awk中不使用匹配()函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要字边界添加到这个awk命令:
I want to add word boundaries to this awk command:
awk '{$0=tolower($0)};/wordA/&&/wordB/ { print FILENAME ":" $0; }' myfile.txt
我尝试添加 \\是
左侧和 wordA
和 wordB 右code>但它并没有在我的测试工作。结果
我试过这样: / \\ ywordA \\ Y /&放大器;&安培; / \\ ywordB \\ Y /
I tried adding \y
at left and right of wordA
and wordB
but it didn't work in my tests.
I tried this: /\ywordA\y/&&/\ywordB\y/
谢谢大家!
(PS:我是新来的awk,所以我试图避免的匹配()函数)
(ps: I'm new to awk so I was trying to avoid the match() function.)
推荐答案
您想使用呆子,而不是awk的:
You want to use gawk instead of awk:
gawk '{$0=tolower($0)};/\ywordA\y/&&/\ywordB\y/ { print FILENAME ":" $0; }' myfile.txt
会做你想要什么,如果你的系统有GAWK(例如在Mac OS X)。 \\ y是一个GNU扩展AWK。
will do what you want, if your system has gawk (e.g. on Mac OS X). \y is a GNU extension to awk.
这篇关于如何使用Word边界awk中不使用匹配()函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文