假设我有这张表:
one two three four
two three four five
three four five six
four five six seven
five six seven eight
所以我写awk -v word=two '$0 ~ "[^[:alpha:]]" word "[^[:alpha:]]"'
了此链接访问所有具有二.结果是整行:
one two three four
two three four five
如果我只想查找 3 美元,我应该为该命令添加什么?
如果我想在互联网上搜索答案。我应该搜索什么?或者说这很简单:(问题涉及 AWK 的哪个主题?
答案1
您必须使用{print$n}
来打印第 n 个单词。因此,对于您的情况,它将是{print$3}
最终命令如下:
awk -v word=two '$0 ~ "[^[:alpha:]]" word "[^[:alpha:]]" {print$3}'
这将给出输出
three
four