Operating System - Linux
1828584 Members
2507 Online
109982 Solutions
New Discussion

Re: get certain fields within an output

 
SOLVED
Go to solution
lawrenzo_1
Super Advisor

get certain fields within an output

Hi all,

more awk help needed please:

I want to print some information in awk:

info1 info2 info3 info4
info5 info6 info7 info8
info9 info10 info11 info12
info13 info14 info15 info16

this is an example output ...

how do I use awk to print info4, info8 and info 12 please, the only common denominator in the sting is PP however this string will appear in info5 and info9 for example.

hope this makes sense!

Thanks in advance.

Chris
hello
6 REPLIES 6
Jeff_Traigle
Honored Contributor
Solution

Re: get certain fields within an output

In your case, the content of the field doesn't matter. You're wanting the fourth field of each line. Assuming the data is in a file called datafile:

awk '{print $4}' datafile
--
Jeff Traigle
lawrenzo_1
Super Advisor

Re: get certain fields within an output

doh,

as easy as that ....

I knew this but wasnt thinking ...

Thanks for the help.
hello
perumal_2
Frequent Advisor

Re: get certain fields within an output

Hi Chris

In awk $"column number" displays the whole column values.
lets say for example you wnat to print 4th cloumn you may use
awk '{print $4}'. I assume from your query that you wanted to print the whole 4th column, though you had missed info16

rgds
perumal
SANTOSH S. MHASKAR
Trusted Contributor

Re: get certain fields within an output

Hi,

Use following if ur i/p to awk is

info1 info2 info3 info4
info5 info6 info7 info8
info9 info10 info11 info12
info13 info14 info15 info16
--------------------------
# awk '{print $4}'
--------------------------

but I don't understand what do u mean by this

--------------------------
how do I use awk to print info4, info8 and info 12 please, the only common denominator in the sting is PP however this string will appear in info5 and info9 for example.
---------------------------

Pl. elaborate above.
lawrenzo_1
Super Advisor

Re: get certain fields within an output

ok thannks guys,

I wasnt thinking straight:

my solution is

awk '/PPs:/ {print $4,$5": "$6}' datafile
hello
lawrenzo_1
Super Advisor

Re: get certain fields within an output

ty
hello