Re: using awk for selective printing, and adding a new line
by Antonio Olivares
> -----Original Message-----
> From: jon(a)jgcomp.com
> Sent: Mon, 09 May 2016 14:49:50 -0400
> To: wingators(a)inbox.com
> Subject: Re: using awk for selective printing, and adding a new line
>
> On Mon, May 09, 2016 at 08:24:54AM -0800, Antonio Olivares wrote:
>> 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
>>
>
> It would be much easier to leave it as one field per line.
>
>
> 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") }
> ' $1
>
> --
Dear Jon,
I like your solution, but I get different output:
$ awk ' BEGIN { f[1] = 4; f[2] = -14 f[3] = f4 = f[5] = f[6] = f[7] = f[8] = f[9] = f[10] = 3 } { printf ("%*s%c",f[NR%10], $0, NR%10 ? " " : "\n") }' tablagr2.dat
awk: syntax error at source line 1
context is
BEGIN { f[1] = 4; f[2] = -14 f[3] >>> = <<< f4 = f[5] = f[6] = f[7] = f[8] = f[9] = f[10] = 3 } { printf ("%*s%c",f[NR%10], $0, NR%10 ? " " : "\n") }
awk: illegal statement at source line 1
$ awk ' BEGIN { f[1] = 4; f[2] = -14; f[3] = f4 = f[5] = f[6] = f[7] = f[8] = f[9] = f[10] = 3 } { printf ("%*s%c",f[NR%10], $0, NR%10 ? " " : "\n") }' tablagr2.dat
Pos. Equipo JJ JG JE JP GF GC DIF PTS 1Monterrey 17 12 1 4 38 23 15 37 2Pachuca 17 8 6 3 31 16 15 30 3 Leon 17 9 3 5 29 19 10 30 4 America 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 CruzAzul 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 ClubQueretaro 17 5 4 8 21 26 -5 19 14 ClubTijuana 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 ChiapasFC 17 3 3 11 16 33 -17 12
$
$ awk ' BEGIN { f[1] = 4; f[2] = -14; f[3] = f4 = f[5] 9] = f[10] = 3 } { printf ("%*s%c",f[NR%10], $0, NR%10 ? " " : "\n") }' tablageneral20160509.dat
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 Leon 17 9 3
5 29 19 10 30
4 America 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 CruzAzul 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 ClubQueretaro 17 5 4
8 21 26 -5 19
14 ClubTijuana 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 ChiapasFC
17 3 3 11 16
33 -17 12
to get the nice output I have to do it in two steps,
1) copy the contents of the website to a file, then
2) run/pipe the command to
awk '{printf("%s ",$0)}' filename > newfilename
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
and then use this one:
awk '{ for (i = 1; i <= NF; i++) if (i % 10) printf "%s\t", $i; else printf "%s\n", $i }' newfilename
Maybe I should just combine it into 1? I wonder what I am doing wrong?
I actually use the commands to fit the data nicely to a latex table as the following:
$ awk '{ for (i = 1; i <= NF; i++) if (i % 10) printf "%s\t", $i; else printf "%s\n", $i }' tablagr2.dat | awk '$1=$1' OFS=' & ' ORS=' \\\\ \\hline \n'
Pos. & Equipo & JJ & JG & JE & JP & GF & GC & DIF & PTS \\ \hline
1 & Monterrey & 17 & 12 & 1 & 4 & 38 & 23 & 15 & 37 \\ \hline
2 & Pachuca & 17 & 8 & 6 & 3 & 31 & 16 & 15 & 30 \\ \hline
3 & Leon & 17 & 9 & 3 & 5 & 29 & 19 & 10 & 30 \\ \hline
4 & America & 17 & 8 & 5 & 4 & 34 & 22 & 12 & 29 \\ \hline
5 & Chivas & 17 & 7 & 7 & 3 & 26 & 16 & 10 & 28 \\ \hline
6 & Morelia & 17 & 8 & 4 & 5 & 25 & 24 & 1 & 28 \\ \hline
7 & Santos & 17 & 8 & 3 & 6 & 22 & 20 & 2 & 27 \\ \hline
8 & Tigres & 17 & 6 & 6 & 5 & 29 & 19 & 10 & 24 \\ \hline
9 & CruzAzul & 17 & 5 & 7 & 5 & 25 & 24 & 1 & 22 \\ \hline
10 & Pumas & 17 & 5 & 7 & 5 & 23 & 24 & -1 & 22 \\ \hline
11 & Toluca & 17 & 5 & 7 & 5 & 20 & 21 & -1 & 22 \\ \hline
12 & Puebla & 17 & 5 & 7 & 5 & 21 & 26 & -5 & 22 \\ \hline
13 & ClubQueretaro & 17 & 5 & 4 & 8 & 21 & 26 & -5 & 19 \\ \hline
14 & ClubTijuana & 17 & 3 & 9 & 5 & 17 & 26 & -9 & 18 \\ \hline
15 & Atlas & 17 & 3 & 5 & 9 & 18 & 26 & -8 & 14 \\ \hline
16 & Dorados & 17 & 4 & 2 & 11 & 18 & 32 & -14 & 14 \\ \hline
17 & Veracruz & 17 & 2 & 8 & 7 & 18 & 34 & -16 & 14 \\ \hline
18 & ChiapasFC & 17 & 3 & 3 & 11 & 16 & 33 & -17 & 12 \\ \hline
The names are in two, Cruz Azul, combined into Cruz Azul, Chiapas FC -> ChiapasFC, Club Tijuana, Club Queretaro, I have to combine them into 1 so the data can format nicely. If the commands could be combined to do it in one shot, it would be nice, but the names will be a problem.
The data is from :
http://www.mediotiempo.com/tabla_general.php?id_liga=1&id_torneo=591
I select copy the data and paste it into a file, then I have to remove the "\n" and then take the 10 items per line. It looks easy, but it takes some time.
Thanks for your help.
Best Regards,
Antonio
____________________________________________________________
Can't remember your password? Do you need a strong and secure password?
Use Password manager! It stores your passwords & protects your account.
Check it out at http://mysecurelogon.com/password-manager
7 years, 11 months
using awk for selective printing, and adding a new line
by 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
____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!
7 years, 11 months
android & fedora 23 & thunar
by François Patte
Bonjour,
I would like to plug a tablet running android with a computer running
fc23 and copy files from the tablet to the computer and conversely from
the computer to the tablet.
I installed simple-mtpfs and gvfs-mtp
I can mount the tablet using the command: simple-mtpf android
I can see the content of the tablet, I can copy a file from the tablet
to the computer *but* I can't copy a file from the computer to the
tablet and I have a strange error message: I right click on the file (on
the computer) and choose "copy", then I go to ~/android and choose
"paste", the message is: "/home/me/android/file does not exist"
Of course it does not exist because I want to copy it in the directory
/home/me/android/
What can I do to tranfert files from the computer to the tablette?
2nd question: is there a way to automatically mount the tablet when it
is plugged to the computer? I use xfce and thunar as file manager.
Thank you.
--
François Patte
UFR de mathématiques et informatique
Laboratoire CNRS MAP5, UMR 8145
Université Paris Descartes
45, rue des Saints Pères
F-75270 Paris Cedex 06
Tél. +33 (0)1 8394 5849
http://www.math-info.univ-paris5.fr/~patte
7 years, 11 months
[SOLVED] Fedora 23: clementine / mp3
by Frank Elsner
Hello,
just to inform you what solved my problem:
clementine 1.3.x needs gstreamer1-plugins-ugly from rpmfusion-free-updates-testing
to handle mp3 files.
Thanks to all who gave me hints.
--Frank Elsner
7 years, 11 months
older packages
by Patrick Dupre
Hello,
where can I find a previous version of a rpm package?
Thank
===========================================================================
Patrick DUPRÉ | | email: pdupre(a)gmx.com
Laboratoire de Physico-Chimie de l'Atmosphère | |
Université du Littoral-Côte d'Opale | |
Tel. (33)-(0)3 28 23 76 12 | | Fax: 03 28 65 82 44
189A, avenue Maurice Schumann | | 59140 Dunkerque, France
===========================================================================
7 years, 11 months
Q re: systemctl
by JD
Got this weird message:
Failed to start lib-systemd-system-rc\x2dlocal.service.mount: Unit
lib-systemd-system-rc\x2dlocal.service.mount failed to load: No such
file or directory
after I tried to enable rc-local.service
which turns out it cannot be done.
As of now, /etc/rc.d/rc.local is NOT being run at boot
Anything I can do the change that?
Yes, /etc/rc.d/rc.local is executable and readable by root
and contains the proper script that looks at the args start stop ...etc.
Thanx!!
7 years, 11 months
Chess (again)
by Timothy Murphy
Many years ago I used to play gnuchess
which used to give a hint (IIRC) of the best next move,
if requested.
As far as I can see no hint is offered in gnuchess today.
I was surprised to see that the gnu.chess newsgroup
does not appear to have had any posting for over a year.
Is gnuchess effectively dead?
If so, is there a reasonably good alternative, offering hints?
--
Timothy Murphy
gayleard /at/ eircom.net
School of Mathematics, Trinity College, Dublin
7 years, 11 months
cdrecord and 8.5GB dual layer DVD's
by JD
I have a dual layer dvd burner, and dual layer DVD media.
Running fc22 64 bit.
Burning an 8.2GB file to the medium dies at byte 4060348416
with
Track 01: 3872 of 7740 MB written (fifo 99%) [buf 100%] 2.0x.cdrecord:
Input/output error. write_g1: scsi sendcmd: no error
CDB: 2A 00 00 1E 40 80 00 00 10 00
status: 0x2 (CHECK CONDITION)
Sense Bytes: F1 00 04 00 1E 3D E0 0A 00 32 7F 13 09 90 00 00
Sense Key: 0x4 Hardware Error, deferred error, Segment 0
Sense Code: 0x09 Qual 0x90 (track following error) [No matching
qualifier] Fru 0x0
Sense flags: Blk 1981920 (valid)
cmd finished after 1.151s timeout 200s
write track data: error after 4060348416 bytes
cdrecord: A write error occured.
cdrecord: Please properly read the error message above.
Writing time: 1512.651s (00:25:12.651)
Average write speed 3.9x.
Min drive buffer fill was 4%
Total of 1 possible drive buffer underruns predicted.
Fixating...
Fixating time: 0.002s (00:00:00.002)
cdrecord: fifo had 124040 puts and 123913 gets.
cdrecord: fifo was 2 times empty and 69171 times full, min fill was 0%.
The kernel detects the drive as follows:
May 05 18:16:28 localhost kernel: sr 1:0:0:0: [sr0] scsi3-mmc drive:
24x/24x writer dvd-ram cd/rw xa/form2 cdda tray
So, it seems the drive does not handle dual layer media????
What does your kernel say about your dual layer dvd burner?
7 years, 11 months
mate-session-save is a NOP
by JD
It does absolutely NOTHING.
Why is it even released?
After running it, I reboot and login.
Nothing is restored.
7 years, 11 months