using awk with column value conditions using awk with column value conditions shell shell

using awk with column value conditions


If you're looking for a particular string, put quotes around it:

awk '$1 == "findtext" {print $3}'

Otherwise, awk will assume it's a variable name.


This method uses regexp, it should work:

awk '$2 ~ /findtext/ {print $3}' <infile>


Depending on the AWK implementation are you using == is ok or not.

Have you tried ~?. For example, if you want $1 to be "hello":

awk '$1 ~ /^hello$/{ print $3; }' <infile>

^ means $1 start, and $ is $1 end.