Find a field number for a value in text file - BASH
I'm trying to find a bash solution to return the field number for a string in a tab-delimited text file. Anyone have an idea?
|
awk -Ft would parse a line using tabs as delimiters.
You could do something like: Code:
FLDCNT=1 Of course you'd put in whatever word/pattern you're looking for in palce of <pattern> and your text file name in place of <file>. Note this gives you the field number per line so if you had it on more than one line you could see multiple field numbers (one for each line it is found on). |
With gawk you can try
Code:
gawk '{split($0,array,"\t"); for (x in array) if (array[x] == "string") {print x}}' filename.txt Code:
gawk '{split($0,array,"\t"); for (x in array) if (match(array[x],"substring") > 0) {print x}}' filename.txt |
[QUOTE=colucix]With gawk you can try
Code:
gawk '{split($0,array,"\t"); for (x in array) if (array[x] == "string") {print x}}' filename.txt ___________________ Thanks so very much! That was exactly what I needed. I appreciate all your help! |
All times are GMT -5. The time now is 08:20 AM. |