bash/awk question
Assume file.txt contains the following data.
of yes
am kill
do die
I want awk to print out yes (which is the 2nd column of the first row) if the first column of the first row is of. Heres my code which doesn't work.
bash-4.1$ x=of
bash-4.1$ awk '$1 == $'x' {print $2}' file.txt
In java it would be possible using the equals operator. awk doesn't have it.
Also I don't want to use
awk '$1 == "of" {print $2}' file.txt
since I'm doing the matching on a large scale so I have to store it in a variable.
Any kind of help would be appreciated.
|