|
|
Question : Awk - printing fixed width lines
|
|
Using, AWK, I need to print out lines that are fixed width. I'll have 4 columns of various lengths. In the output, each columns will have a specific starting position and spaces till the start of the next column. For example, if: $1=12345 $2=This is a test $3= (blank) $4=999
Then output: 12345 This is a test 999 \n(EndOfLine) ^ ^ ^ ^ $1 $2 $3 $4
Notice that some columns could be blank.
Anyone have a ideas?
|
Answer : Awk - printing fixed width lines
|
|
Use awk's printf function for output and specificy widths in the format Something like this:
printf("%-9s%-19s%-5s\n", $1, $2, $3, $4);
|
|
|
|
|