LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Closed Thread
  Search this Thread
Old 11-15-2010, 02:50 PM   #1
ghantauke
Member
 
Registered: Nov 2010
Posts: 114

Rep: Reputation: 6
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.
 
Old 11-15-2010, 03:20 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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/
 
  


Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
awk question on handling *.CSV "text fields" in awk jschiwal Programming 8 05-27-2010 06:23 AM
[SOLVED] BASH Script, 'awk' and 'if' question. lupusarcanus Linux - Newbie 7 03-14-2010 11:07 AM
N00b's bash, sed, or awk question petcherd Slackware 5 08-01-2007 06:42 AM
Simple bash/awk/sed scripting question R00ts Programming 4 04-16-2005 02:55 AM
Bash script question (grep and awk) hamish Linux - Software 6 04-06-2005 03:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration