-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathfield_header_position.awk
More file actions
44 lines (40 loc) · 869 Bytes
/
field_header_position.awk
File metadata and controls
44 lines (40 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/awk -f
#
# script to find out the position (column) of a selected field. the case of
# the fields is ignored.
#
# a value for variable "fieldname" must be passed to this script. it defines which
# field/column should be used
#
# example call of this script:
#
# field_query_header.awk -v fieldname=country /home/testuser/testfile.csv
#
#
# uwe.geercken@datamelt.com
# http://datamelt.com
#
# last update: 2010-02-02
#
#
# begin of processing
BEGIN {
# setting the file's field seperator
FS=";";
fieldnumber="[not found]";
}
# first line is the header row. we retrieve the number of the selected field
NR <= 1 {
for (i=1; i<=NF;i++)
{
if(tolower(fieldname)==tolower($i))
{
fieldnumber=i;
}
}
}
END {
# give out which field we are using
print "evaluated field name: " fieldname;
print "column in header row: " fieldnumber;
}