Operating System - HP-UX
1751907 Members
4961 Online
108783 Solutions
New Discussion юеВ

Insert tab character into awk print comand string

 
SOLVED
Go to solution
Ed Hon
Regular Advisor

Insert tab character into awk print comand string

I have awk '{print $1" "$2}', but the length of $1 varies, making for a serpentine output unfit for a cut command. How do I insert a tab character where " " is, so that $2 is verically aligned (left justified)? Thanks.
3 REPLIES 3
James R. Ferguson
Acclaimed Contributor
Solution

Re: Insert tab character into awk print comand string

Hi Ed:

Here's one example:

# echo "a b c"|awk '{print $1,"\011",$2,"\011",$3}'

...JRF...
Rodney Hills
Honored Contributor

Re: Insert tab character into awk print comand string

awk allows \t too

echo "a b" | awk '{print $1,"\t",$2}'
There be dragons...
Curtis Larson_1
Valued Contributor

Re: Insert tab character into awk print comand string

and there is printf

printf("%s\t%s\n",$1,$2);

or

printf("%-20s%-20\n",$1,$2);

which will left justify the strings in a 20 character field.