awk正则表达式(awk regular expression)

我正在学习AWK中的正则表达式。 在AWK中[^ ] 匹配任何不在里面的字符 。 现在我需要提取那些不属于任何单词的' a '。

如果我的输入文件是

a aa a+a .a.a bac

输出将是

a+a .a.a

因为+ a.aa不是任何单词所以这些行是打印的。 所以我做了这样的事

awk '/[^[a-z]]a[^[a-z]]/ {print} input_file'

但这不起作用。 请帮忙!

I am learning regular expressions in AWK. In AWK [^ ] matches any character not inside. Now I need to extract those 'a' which are not part of any word like.

If my input file is

a aa a+a .a.a bac

The output will be

a+a .a.a

Because a+a and .a.a are not any words so these lines are printed. So I did something like this

awk '/[^[a-z]]a[^[a-z]]/ {print} input_file'

But this is not working. Please Help!

最满意答案

这可能是你想要的:

$ awk '/[^[:alpha:]]a|a[^[:alpha:]]/' file a+a .a.a

取决于你想要a. 和.a在您的输入文件中处理。

This might be what you want:

$ awk '/[^[:alpha:]]a|a[^[:alpha:]]/' file a+a .a.a

depending on how you want a. and .a in your input file handled.

更多推荐