LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash/awk question (https://www.linuxquestions.org/questions/linux-newbie-8/bash-awk-question-844427/)

ghantauke 11-15-2010 02:50 PM

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.

Tinkster 11-15-2010 03:20 PM

Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate/follow-up to an existing thread...




http://www.linuxquestions.org/questi...estion-844420/


All times are GMT -5. The time now is 07:20 PM.