|
Home > Archive > Unix Shell > November 2007 > formatting question...
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
formatting question...
|
|
| Farid Hamjavar 2007-11-27, 7:21 pm |
|
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 2007-11-27, 7:21 pm |
|
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 2007-11-27, 7:21 pm |
| ["Followup-To:" header set to comp.unix.shell.]
On 2007-11-27, Farid Hamjavar <hamjavar@unm.edu> 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.
|
|
|
|
|