Results 1 to 2 of 2
Let's say I have something similar to the following in a file:
Name,Description,Info,MoreInfo
name1,description1,info1,info2
name2,description2,info2,info2
Where the first line is a title of what each column contains. And the file ...
- 12-01-2010 #1Just Joined!
- Join Date
- Dec 2010
- Posts
- 1
Awk question
Let's say I have something similar to the following in a file:
Name,Description,Info,MoreInfo
name1,description1,info1,info2
name2,description2,info2,info2
Where the first line is a title of what each column contains. And the file could contain the columns in any order. Such as Description,Name,MoreInfo,Info. Instead of what is above.
How can I determine which column contains a certain title?
For example, I need to know which column is the Description column before parsing the file.
- 12-02-2010 #2Linux Enthusiast
- Join Date
- Apr 2004
- Location
- UK
- Posts
- 658
Hi there,
This should sort you out:
Let us know how you get onCode:chris@angua:~/dev/scratch$ cat test.txt Name,Description,Info,MoreInfo name1,description1,info1,info2 name2,description2,info2,info2 chris@angua:~/dev/scratch$ cat pattern.awk { for (i=1; i <= NF; i++) { if ($i == "Description") { print i } } } chris@angua:~/dev/scratch$ head -1 test.txt | awk -F',' -f pattern.awk 2To be good, you must first be bad. "Newbie" is a rank, not a slight.


Reply With Quote