Parnab Sanyal Parnab Sanyal - 3 months ago 10
Linux Question

awk regular expression

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!

Answer

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.

Comments