1753638 Members
5427 Online
108798 Solutions
New Discussion юеВ

awk help

 
SOLVED
Go to solution
lawrenzo_1
Super Advisor

awk help

Hi all,

I am trying to use awk to manipulate some data:

heading1 heading2 heading3
2 4 7
34 45 1

service
xyz 17

I use awk to print the first line after heading:

awk 'NR>1 {print $2}'

i get

4
45

how can I just display the first number in heading2 which shoud be 4?

many thanks
hello
4 REPLIES 4
Dennis Handly
Acclaimed Contributor
Solution

Re: awk help

awk 'NR==2 {print $2}'
Dennis Handly
Acclaimed Contributor

Re: awk help

This is probably much faster if your file has zillions of lines:
$ awk 'NR==2 {print $2; exit 0}'
lawrenzo_1
Super Advisor

Re: awk help

nice one - thanks Dennis

another awk string to add to me bow.

Chris.
hello
Dennis Handly
Acclaimed Contributor

Re: awk help

This has no test for record 2:
awk 'BEGIN { getline; getline; print $2; exit 0}'