dendenners
Programmer
Hi there,
I'm trying to use printf in awk to format some text a certain way. However I'm encountering problems when passing in the text to awk as a shell variable when the variable contains spaces. Say I want to use the text "hello there" as my formatable text. The following works fine:
echo "" | awk '{printf("%-16.16s", "hello there"}'
However, say I set header="hello there" in the shell and try
echo "" | awk '{printf("%-16.16s", '$header')}'
I get a parse error because of the space in the variable. How can I print this properly? Thanks
Denis
I'm trying to use printf in awk to format some text a certain way. However I'm encountering problems when passing in the text to awk as a shell variable when the variable contains spaces. Say I want to use the text "hello there" as my formatable text. The following works fine:
echo "" | awk '{printf("%-16.16s", "hello there"}'
However, say I set header="hello there" in the shell and try
echo "" | awk '{printf("%-16.16s", '$header')}'
I get a parse error because of the space in the variable. How can I print this properly? Thanks
Denis