formatting question...

formatting question...

am 27.11.2007 23:08:02 von Farid Hamjavar

Hello,


My un-formatted data file:

2007-10 14,807 1,604 29,600
2007-09 15,173 521 35,853
2007-08 12,799 1,236 516
2007-07 5,780 416 37,135


I run it through:

cat file| awk '{printf "%-11s%-7s%-9s%s\n",$1,$2,$3,$4}'


and get:

[I hope you use ASCII friendly mail/news-reader client]


2007-10 14,807 1,604 29,600
2007-09 15,173 521 35,853
2007-08 12,799 1,236 516
2007-07 5,780 416 37,135



But what I want is:
i.e. entries in col# 2,3,4 line up on the
3-digit bound Eries:

2007-10 14,807 1,604 29,600
2007-09 15,173 521 35,853
2007-08 12,799 1,236 516
2007-07 5,780 416 37,135


Anything I can do to get this format?

Thanks,
Farid

Re: formatting question...

am 27.11.2007 23:13:43 von Ed Morton

On 11/27/2007 4:08 PM, Farid Hamjavar wrote:
> Hello,
>
>
> My un-formatted data file:
>
> 2007-10 14,807 1,604 29,600
> 2007-09 15,173 521 35,853
> 2007-08 12,799 1,236 516
> 2007-07 5,780 416 37,135
>
>
> I run it through:
>
> cat file| awk '{printf "%-11s%-7s%-9s%s\n",$1,$2,$3,$4}'

UUOC:

awk '{printf "%-11s%-7s%-9s%s\n",$1,$2,$3,$4}' file

>
> and get:
>
> [I hope you use ASCII friendly mail/news-reader client]
>
>
> 2007-10 14,807 1,604 29,600
> 2007-09 15,173 521 35,853
> 2007-08 12,799 1,236 516
> 2007-07 5,780 416 37,135
>
>
>
> But what I want is:
> i.e. entries in col# 2,3,4 line up on the
> 3-digit bound Eries:
>
> 2007-10 14,807 1,604 29,600
> 2007-09 15,173 521 35,853
> 2007-08 12,799 1,236 516
> 2007-07 5,780 416 37,135
>
>
> Anything I can do to get this format?

Yes, get rid of the "-" signs tellling printf to push everything to the left, e.g.:

$ awk '{printf "%7s%9s%9s%9s\n",$1,$2,$3,$4}' file
2007-10 14,807 1,604 29,600
2007-09 15,173 521 35,853
2007-08 12,799 1,236 516
2007-07 5,780 416 37,135

Regards,

Ed.

Re: formatting question...

am 27.11.2007 23:29:42 von Bill Marcum

["Followup-To:" header set to comp.unix.shell.]
On 2007-11-27, Farid Hamjavar wrote:
>
>
>
> Hello,
>
>
> My un-formatted data file:
>
> 2007-10 14,807 1,604 29,600
> 2007-09 15,173 521 35,853
> 2007-08 12,799 1,236 516
> 2007-07 5,780 416 37,135
>
>
> I run it through:
>
> cat file| awk '{printf "%-11s%-7s%-9s%s\n",$1,$2,$3,$4}'
>
>
> and get:
>
> [I hope you use ASCII friendly mail/news-reader client]
>
>
> 2007-10 14,807 1,604 29,600
> 2007-09 15,173 521 35,853
> 2007-08 12,799 1,236 516
> 2007-07 5,780 416 37,135
>
>
>
> But what I want is:
> i.e. entries in col# 2,3,4 line up on the
> 3-digit bound Eries:
>
> 2007-10 14,807 1,604 29,600
> 2007-09 15,173 521 35,853
> 2007-08 12,799 1,236 516
> 2007-07 5,780 416 37,135
>
>
> Anything I can do to get this format?
>
The '-' in %-99s tells printf to print aligned left, and you want
the fields aligned right.