Dear Help,
I have an i/p file which looks like :
1 24 980
10 97 345
100 67 345
2 945 325
20 8 234
Is there a way to print it like, below format
1 24 980
10 97 345
100 67 345
2 945 325
20 8 234
Thx
Dear Help,
I have an i/p file which looks like :
1 24 980
10 97 345
100 67 345
2 945 325
20 8 234
Is there a way to print it like, below format
1 24 980
10 97 345
100 67 345
2 945 325
20 8 234
Thx
Check format specifiers in printf()
Hello Indra2011,
Could you please try following and let me know if this helps.
This will only work for 3 fields.
awk 'FNR==NR{A=length($1)>A?length($1):A;D=length($2)>D?length($2):D;C=length($3)>C?length($3):C;next} {printf "%"A"d %"D"d %d\n",$1, $2, $3}' Input_file Input_file
Output will be as follows.
1 24 980
10 97 345
100 67 345
2 9845 325
20 8 234
Thanks,
R. Singh
As anbu23 said, printf (builtin in recent shells) will do what you want:
while read A B C; do printf "%3d %3d %3d\n" $A $B $C; done < file
1 24 980
10 97 345
100 67 345
2 945 325
20 8 234