Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

formatting question...

13 views
Skip to first unread message

Farid Hamjavar

unread,
Nov 27, 2007, 5:08:02 PM11/27/07
to

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


Ed Morton

unread,
Nov 27, 2007, 5:13:43 PM11/27/07
to

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.

Bill Marcum

unread,
Nov 27, 2007, 5:29:42 PM11/27/07
to
["Followup-To:" header set to comp.unix.shell.]
The '-' in %-99s tells printf to print aligned left, and you want
the fields aligned right.
0 new messages