Re: Refer to field headings?
- From: Ed Morton <morton@xxxxxxxxxxxxxx>
- Date: Tue, 27 Nov 2007 14:44:02 -0600
On 11/27/2007 2:30 PM, Sashi wrote:
Hi all,
I have a comma delimited text file which I'm parsing with awk. The
first line consists of field names and the rest of the lines have the
values.
Is it possible in [g]awk to refer to the field names instead of
positions?
For example,
awk '( $4 ~ /ASPAC/) {do something;}' < input_file
awk '( region_name ~ /ASPAC/) {do something;}' < input_file
where region_name is the title for the fourth field.
Thanks,
Sashi
I think what you want is something like this:
awk 'NR==1 {for (i=1;i<=NF;i++) f[$i]=i; next}
$f["region_name"] ~ /ASPAC/) {do something}' input_file
Regards,
Ed.
.
- Follow-Ups:
- Re: Refer to field headings?
- From: Ed Morton
- Re: Refer to field headings?
- References:
- Refer to field headings?
- From: Sashi
- Refer to field headings?
- Prev by Date: Refer to field headings?
- Next by Date: Re: Refer to field headings?
- Previous by thread: Refer to field headings?
- Next by thread: Re: Refer to field headings?
- Index(es):
Relevant Pages
|