Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print a specific column

Status
Not open for further replies.

jdhahbi

Technical User
Oct 7, 2009
24
US
Hi
I want to print column2 if column1 is b with:

Code:
awk '$1==b {print $2}' infile > outfile

infile
a 1
b 2
c 3
b 4
e 5
b 6
please help
joseph
the outfile is empty.

it should look like this:
2
4
6

 
Try to compare with the string literal "b" instead of just the name b.

Right now you're comaparing with an uninitialized (so zero value) variable called b, so only if column 1 is zero your print $2 instruction would run.

HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top