Re: using awk for selective printing, and adding a new line

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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, I can get them to one line using awk '{printf("%s ",$0)}' and the filename here, but what I want to do is to get the first 11 records and print out a new line "\n", then get the next 11 record and get new line "\n"

I get the data from mediotiempo.com,

data:

Pos.      Equipo        JJ      JG      JE      JP      GF      GC      DIF    PTS 1     Monterrey       17      12      1       4       38      23      15     37 2     Pachuca         17      8       6       3       31      16      15     30 3     León    17      9       3       5       29      19      10      30 4   América          17      8       5       4       34      22      12      29 5   Chivas   17      7       7       3       26      16      10      28 6    Morelia         17      8       4       5       25      24      1       28 7    Santos  17      8       3       6       22      20      2       27 8    Tigres         17       6       6       5       29      19      10      24 9    Cruz Azul      17       5       7       5       25      24      1       22 10   Pumas   17     5        7       5       23      24      -1      22 11   Toluca          17     5        7       5       20      21      -1      22 12   Puebla          17     5        7       5       21      26      -5      22 13   Club Querétaro         17       5       4       8       21      26      -5      19 14   Club Tijuana   17       3       9       5       17      26      -9      18 15   Atlas   17     3        5       9       18      26      -8      14 16   Dorados         17     4        2       11      18      32      -14     14 17   Veracruz        17     2        8       7       18      34      -16     14 18   Chiapas FC      17     3        3       11      16      33      -17     12

to

Pos Equipo          JJ  JG  JE  JP  GF  GC DIF PTS
 1 Monterrey       16  12   1   3  37  21  16  37
 2 America         16   8   4   4  33  21  12  28
 3 Pachuca         16   7   6   3  29  15  14  27
 4 Leon            16   8   3   5  28  19   9  27
 5 Santos          16   8   3   5  22  19   3  27
 6 Chivas          16   6   7   3  25  16   9  25
 7 Morelia         16   7   4   5  23  23   0  25
 8 CruzAzul        16   5   7   4  25  21   4  22
 9 Tigres          16   5   6   5  26  19   7  21
10 Pumas           16   5   6   5  22  23  -1  21
11 Toluca          16   4   7   5  18  20  -2  19
12 ClubQueretaro   16   5   4   7  20  23  -3  19
13 Puebla          16   4   7   5  18  25  -7  19
14 ClubTijuana     16   3   8   5  17  26  -9  17
15 Dorados         16   4   2  10  18  31 -13  14
16 Veracruz        16   2   8   6  17  32 -15  14
17 Atlas           16   3   4   9  18  26  -8  13
18 ChiapasFC       16   3   3  10  15  31 -16  12

using a sed command.

I have parts of commands as follows:

#!/bin/sh

# Check for arguments
if [ $# -eq 0 ]; then
    echo "Usage: $(basename $0) filename"
    exit 1
fi

if [ ! -f $1 ]; then
    echo "File "$1" doesn't exist!"
    exit 0
fi

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.

Alexander

--
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
http://lists.fedoraproject.org/admin/lists/users@xxxxxxxxxxxxxxxxxxxxxxx
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



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux