Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
formatting question...
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Farid Hamjavar  
View profile  
 More options Nov 27 2007, 5:08 pm
Newsgroups: comp.lang.awk, comp.unix.shell
From: Farid Hamjavar <hamja...@unm.edu>
Date: Tue, 27 Nov 2007 15:08:02 -0700
Local: Tues, Nov 27 2007 5:08 pm
Subject: formatting question...

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ed Morton  
View profile  
 More options Nov 27 2007, 5:13 pm
Newsgroups: comp.lang.awk, comp.unix.shell
From: Ed Morton <mor...@lsupcaemnt.com>
Date: Tue, 27 Nov 2007 16:13:43 -0600
Local: Tues, Nov 27 2007 5:13 pm
Subject: Re: formatting question...

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

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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bill Marcum  
View profile  
 More options Nov 27 2007, 5:29 pm
Newsgroups: comp.lang.awk, comp.unix.shell
Followup-To: comp.unix.shell
From: Bill Marcum <marcumb...@bellsouth.net>
Date: Tue, 27 Nov 2007 17:29:42 -0500
Local: Tues, Nov 27 2007 5:29 pm
Subject: Re: formatting question...
["Followup-To:" header set to comp.unix.shell.]
On 2007-11-27, Farid Hamjavar <hamja...@unm.edu> wrote:

The '-' in %-99s tells printf to print aligned left, and you want
the fields aligned right.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »