使用 AWK 查找单词

Moh*_*ani 3 awk text-processing

有没有办法在整行中找到特定的记录?

这是我的文件:

one two three four
two three four five
three four five six
four five six seven
five six seven eight
Run Code Online (Sandbox Code Playgroud)

如何搜索包含两行的所有行?

Oli*_*Oli 5

awk '/(^| )two( |$)/' ...
Run Code Online (Sandbox Code Playgroud)

(..)那里的团体试图确保我们只匹配“两个”。在前面,它需要是行的开头或空格,在末尾,它需要是空格或行的结尾。简而言之,我们要确保该字段等于 2。

嗯,显然你也可以使用词边界标签(看起来更优雅但不那么便携):

awk '/\<two\>' ...
Run Code Online (Sandbox Code Playgroud)

不确定您的具体用例是什么(我认为它不是数字),您可能也不错,grep -E '\<two\>' ...awk如果您需要做其他事情,会给您更多的灵活性。