Renumber column using Awk

I have a data set similar to that below and I need to add a column $2 (which numbers the lines from 1- end)

Text Input Output x y z
Text Input Output x y z
Text Input Output x y z
Text Input Output x y z

I also need to have various column widths so $1 is 6 spaces $2 is 5, $3 is 5, $4 is 7. I have used awk '{print FNR "\t" $2}' and now have a tab delineated file (which is numbered). Can anyone help adjusting the output? I do not understand how to use the printf commands to specify column width.

Thank you for any assistance you are willing to share

printf uses a format string.


awk '{ printf("%6d\t%5s\t%5s\t%7s\n", $1, $2, $3, $4) }' filewithnumbercolumn > newfile
1 Like