I have a file that contains several fields separated by a tab. I am trying to print all the columns except the first, but I want to print them in just one column with AWK. File format
col 1 col 2 ... col n
There are at least 2 columns in one row.
Example
2012029754 901749095
2012028240 901744459 258789
2012024782 901735922
2012026032 901738573 257784
2012027260 901742004
2003062290 901738925 257813 257822
2012026806 901741040
2012024252 901733947 257493
2012024365 901733700
2012030848 901751693 260720 260956 264843 264844
So, I want to say awk to print column 2 in column n for n greater than 2 without printing blank rows when there is no information in column n of this row, all in one column, as shown below.
901749095
901744459
258789
901735922
901738573
257784
901742004
901738925
257813
257822
901741040
901733947
257493
901733700
901751693
260720
260956
264843
264844
This is the first time I'm using awk, so bear with me. I wrote this from the command line, which works:
awk '{i=2;
while ($i ~ /[0-9]+/)
{
printf "%s\n", $i
i++
}
}' bth.data
This is more of an endorsement for the search than the question of whether this is the right way to do something similar in AWK or is there a better / shorter way to do this.
, .