Suppose I have a pipe separated file like:
|Sr|Fruits|Colors|
|1 |apple |red|
|2 |orange |orange
|3 |grapes |purple|
Here it is evident using awk
that, $2
is Fruits and $3
is the colors column.
In future if the order of the columns change, is it possible to determine the column number using the string?
I.e Colors is $3
and Fruits is $2
?
|foo|bar|
is actually 4 fields but the 1st and 4th are empty. To have two fields, you would wantfoo|bar
. – terdon♦ yesterday