Andrew
Andrew

Reputation: 3

awk fetching specific line and specific field

I need some help with awk. My aim is to fetch in a bunge of lines the seventh line and within that seventh line the fifth field. After reading some manuals about awk, I decided to do it like this, without having the result I wanted. Any hint would be great. Thanks in advance.

awk {OFS=":"};{if (NR == 8) {print $5} else if (NR == 7) {print $5} } ;

Upvotes: 0

Views: 138

Answers (1)

Jotne
Jotne

Reputation: 41446

It may be some like this you want:

awk -F: 'NR==7 || NR==8 {print $5}' file

It will print the fifth field of line 7 and 8

Can also be written:

awk  -F:  'NR~/^(7|8)$/ {print $5}' file

Upvotes: 2

Related Questions