On Mon, May 09, 2016 at 11:50:38AM -0800, Antonio Olivares wrote:
> 
> >> From: ad+li...@uni-x.org
> >> Sent: Mon, 9 May 2016 20:47:49 +0200
> >> To: users@lists.fedoraproject.org
> >> Subject: Re: using awk for selective printing, and adding a new line
> >> 
> >> Am 09.05.2016 um 18:24 schrieb Antonio Olivares:
> >>> Dear folks,
> >>> 
> >>> I have found numerous guides using awk to format stats.  I can get
> >>> stats
> >>> from a website, but when I paste them they get pasted one per line,

<snip>
> >>> 
> >>> awk '
> >>> 
> >>> NR == 1 {
> >>>         printf "%2s %-14s %3s %3s %3s %3s %3s %3s %3s %3s \n",
> >>>                 "Pos", "Equipo", "JJ", "JG", "JE", "JP", "GF", "GC" ,
> >>> "DIF", "PTS"
> >>> }
> >>> 
> >>> NR >= 2 {
> >>>         printf "%2d %-14s %3d %3d %3d %3d %3d %3d %3d %3d \n",
> >>>                  $1, $2, $3, $4, $5, $6, $7, $8, $9, $10 '\n'
> >>> }' $1
> >>> 
> >>> but it just prints the first line and that is it because it treats the
> >>> data as a single line.  If that is possible otherwise I will have to do
> >>> it manually.
> >>> 
> >>> Best regards,
> >>> 
> >>> 
> >>> Antonio
> >> 
> >> 
> >> If you manage that the club names are always single fields of a
> >> reasonable length, then
> >> 
> >> awk '{ for (i = 1; i <= NF; i++) if (i % 10) printf "%s\t", $i; else
> >> printf "%s\n", $i }' $yourinputfile
> >> 
> >> does what you want.
> >> 
> > 
> > It is getting close but some formatting is messing it up
> > I tried
> > 
> > $ awk 'ORS=NR%10?" ":"\n"' $filename
> > 
> > it looked like it was going to work, but then in the first line, the PTS
> > and the 1 got tangled up.  Thank you for your insight it is close.  I
> > might need to use tr -d '\n' filename and pipe this and it could work.
> > 
> > Best Regards,
> > 
> > 
> > Antonio
> > 
> 
> awk '{ for (i = 1; i <= NF; i++) if (i % 10) printf "%s\t", $i; else printf 
> "%s\n", $i }'
> 
> worked :)  
> 
> Dear folks,
> 
> I saw a mistake.  The command worked, I saw that the names were split into 
> two and that messed things up.  By fixing the names into one, the command 
> works.  Thank you very much for your help.
> 
> Best Regards,
> 

If you leave the data as one field per line you can avoid squishing
the team names and not depend on tabs for alignment.

awk '
BEGIN { f[1] = 4; f[2] = -14
        f[3] = f[4] = f[5] = f[6] = f[7] = f[8] = f[9] = f[10] = 3
}
{ printf ("%*s%c", f[NR%10], $0, NR%10 ? " " : "\n") }
' <data>


-- 
Jon H. LaBadie                  jo...@jgcomp.com
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
http://lists.fedoraproject.org/admin/lists/users@lists.fedoraproject.org
Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org

Reply via email to