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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AWK including headers

Status
Not open for further replies.

Mike2011

Programmer
Joined
May 26, 2011
Messages
2
Hi guys,

I'd recently the problem to include the header row in my result set.

This is my awk command:
bzcat .....txt.bz2 |awk '{if($1=="2011-05-17"&&$3=="2342"&&$6=="2452"){print $1,$3,$6}}'

I've tried the following:
1. bzcat .....txt.bz2 |awk '{if($1=="2011-05-17"&&$3=="2342"&&$6=="2452"){print $1,$3,$6}}' | head -0

2. bzcat .....txt.bz2 | head -0 | awk '{if($1=="2011-05-17"&&$3=="2342"&&$6=="2452"){print $1,$3,$6}}'

Both approaches didn't work. Any ideas what I'm doing wrong?

Much appreciate,
Mike
 
What are you trying to do? head -0 prints the first zero lines of input, i.e. nothing

CaKiwi
 



It's not clear what you want, but assuming it's to print the first line, then do this:
Code:
bzcat .....txt.bz2 |\
awk '
{if(NR==1){print $1,$3,$6};
 if($1=="2011-05-17"&&$3=="2342"&&$6=="2452"){print $1,$3,$6}
}'
[3eyes]



----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
You wanted this ?
Code:
bzcat .....txt.bz2 |awk '{if(NR==1||($1=="2011-05-17"&&$3==2342&&$6==2452))print $1,$3,$6}'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks guys for your help!

The suggestion from PHV did the job!

Thanks,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top