December 20, 2018

This course is easy

if you do the correct things

  • First, you need to understand the question in your own language
    • Make a drawing
  • Decompose the problem in smaller parts
    • You can eat an elephant, piece by piece
  • Write your answer in your own words
  • Translate them to the computer language
    • In this case, awk

You learn what you do

If you play piano, you learn piano

If you dance, you learn dancing

If you sit and watch the screen, you learn how to sit and watch the screen

If you memorize and repeat, you learn how to repeat

If you write your own programs, you learn to program

What is learning?

There are three levels of learning

  • Knowing that …
    • e.g. knowing that awk is a computer language
  • Knowing how …
    • e.g. knowing how to use awk
  • Understanding
    • e.g. knowing why to use awk
    • e.g. transferring your knowledge of awk to another computer language
      • Like R, Python, C++, JavaScript, Matlab, Julia, Go, Ruby

Arrays

How many countries on each continent?

awk '$3=="America" {n_America++}
$3=="Africa" {n_Africa++}
$3=="Asia" {n_Asia++}
$3=="Europe" {n_Europe++}
$3=="Oceania" {n_Oceania++}
END {print "America", n_America;
     print "Africa", n_Africa;
     print "Asia", n_Asia;
     print "Europe", n_Europe;
     print "Oceania", n_Oceania;
}' world_2007.txt

Arrays make this easier

awk '$3=="America" {n["America"]++}
$3=="Africa" {n["Africa"]++}
$3=="Asia" {n["Asia"]++}
$3=="Europe" {n["Europe"]++}
$3=="Oceania" {n["Oceania"]++}
END {print "America", n["America"];
     print "Africa", n["Africa"];
     print "Asia", n["Asia"];
     print "Europe", n["Europe"];
     print "Oceania", n["Oceania"];
}' world_2007.txt

$3 is the continent

awk '{n[$3]++}
END {print "America", n["America"];
     print "Africa", n["Africa"];
     print "Asia", n["Asia"];
     print "Europe", n["Europe"];
     print "Oceania", n["Oceania"];
}' world_2007.txt

Repeat commands using for

awk '{n[$3]++}
END {for(continent in n) {
    print continent, n[continent]
    }
}' world_2007.txt

Notice that the output may not be in order

Parts of an array

One array contains several elements

They are pairs of key, and values

We can access the values using []

we write the key inside []

we can read or write the value

array[key] =  value

Exercise: Frequency table

Using the int() function we can round the life expectancy of each country

What is the absolute frequency of each life expectancy?

39 1
42 5
43 2
44 1
45 1
46 4
48 3
49 2
50 3
51 2
52 4
54 3
55 1
56 4
58 3
59 4
60 2
62 2
63 2
64 3
65 4
66 1
67 1
69 1
70 5
71 8
72 12
73 6
74 8
75 6
76 5
77 2
78 10
79 8
80 8
81 3
82 2

split a text

split(s, a [, r])
Split the string s into the array a on the regular expression r, and return the number of fields.
If r is omitted, FS is used instead.
The array a is cleared (deleted) first.

Example: DNA sequencing cost

Take a look at /home/andres/sequencingcostdata.txt

Date     Cost per Mb     Cost per Genome 
Sep-01  5292.39 95263072
Mar-02  3898.64 70175437
Sep-02  3413.80 61448422

How can we transform Date into number of months since January 2000?

First step

  • File is separated by tab
  • First line can be ignored
  • Date is on the first field
    • something like: Sep-02
    • We have to split it in month and year
  • We need to convert month into a number
  • We need a formula for number of months

Skipping lines

There are several ways to ignore the first line

One useful way is the command next

awk 'NR==1 {next} {print $0}' sequencingcostdata.txt

next means skip the rest of the commands and process the next line

Splitting

awk 'NR==1 {next} {split($1, date, "-");
    print $1, date[1], date[2]}' sequencingcostdata.txt

split creates arrays with numeric indices

Answers of Quiz 4

How many lines are there in last.txt?

289

How many lines are there in last.txt?

awk 'END {print NR}' last.txt
289

How many times each user has connected?

Use an AWK array to count each user separately

buse.azm 3
fustunel 3
anaraven 61
berkay_e 2
kadir_mi 7
kelifklc 6
kadeertu 9
alpaslan 12
hilal_ca 10
busrabal 3

How many times each user has connected?

Use an AWK array to count each user separately

awk '{n[$1]++} 
END {for(i in n) {
        print i, n[i]
    }
}' last.txt 
buse.azm 3
fustunel 3
anaraven 61
berkay_e 2
kadir_mi 7
kelifklc 6
kadeertu 9
alpaslan 12
hilal_ca 10
busrabal 3
ziyabay1 8
ansevili 5
mkandemi 16
aayden 12
aysenurt 17
gizemgun 7
andres 4
esengul 1
edasmlgl 2
gamzemer 15
beyza_bh 4
c_nrc_n 11
ecenaz.y 1
dikbas.n 5
kubrakhr 5
berfinba 2
mevlutge 15
begumsek 3
sercihan 14
hamednad 2
cansutun 5
nicat990 1
damla.uz 3
ssohn199 15

Which users forgot to disconnect?

If the line says gone or down, it means that the user did not exit the session correctly. Show who did forgot to disconnect

kelifklc
andres
ziyabay1
kadeertu
alpaslan
hilal_ca
cansutun
ziyabay1
ziyabay1
mevlutge

Which users forgot to disconnect?

If the line says gone or down, it means that the user did not exit the session correctly. Show who did forgot to disconnect

awk '/gone/ {print $1} /down/ {print $1}' last.txt 
kelifklc
andres
ziyabay1
kadeertu
alpaslan
hilal_ca
cansutun
ziyabay1
ziyabay1
mevlutge
alpaslan

How many minutes lasted each connection?

The last column gives the connection time in (hh:mm) format. Use a regular expression to select only lines that match this format. Use the split() command to obtain hours and minutes. Print the first and last columns, and the total of minutes

gamzemer (00:30) 30
anaraven (00:11) 11
fustunel (00:19) 19
ansevili (00:22) 22
aayden (00:26) 26
busrabal (01:11) 71
ansevili (01:03) 63
aayden (02:14) 134
edasmlgl (03:51) 231
anaraven (00:01) 1

How many minutes lasted each connection?

The last column gives the connection time in (hh:mm) format. Use a regular expression to select only lines that match this format. Use the split() command to obtain hours and minutes. Print the first and last columns, and the total of minutes

awk '/\([0-9]{2}:[0-9]{2}\)/ {
    split($NF,a,/[:()]/);
    print $1, $NF, a[3]+60*a[2]}' last.txt
gamzemer (00:30) 30
anaraven (00:11) 11
fustunel (00:19) 19
ansevili (00:22) 22
aayden (00:26) 26
busrabal (01:11) 71
ansevili (01:03) 63
aayden (02:14) 134
edasmlgl (03:51) 231
anaraven (00:01) 1
ansevili (00:09) 9
edasmlgl (01:07) 67
anaraven (00:02) 2
anaraven (02:39) 159
busrabal (02:26) 146
fustunel (02:10) 130
aayden (02:35) 155
aayden (00:12) 12
aayden (00:00) 0
anaraven (01:39) 99
anaraven (00:21) 21
ssohn199 (01:54) 114
anaraven (01:36) 96
ssohn199 (17:04) 1024
ssohn199 (00:06) 6
gamzemer (01:19) 79
sercihan (01:25) 85
sercihan (00:22) 22
anaraven (00:02) 2
anaraven (00:00) 0
anaraven (00:05) 5
anaraven (00:00) 0
gizemgun (01:02) 62
gamzemer (01:16) 76
c_nrc_n (02:13) 133
ziyabay1 (09:51) 591
gamzemer (03:31) 211
gamzemer (20:13) 1213
mevlutge (00:05) 5
mevlutge (05:32) 332
aayden (00:49) 49
aayden (00:00) 0
aayden (00:10) 10
anaraven (02:12) 132
ansevili (01:11) 71
anaraven (01:20) 80
busrabal (01:09) 69
fustunel (01:23) 83
ansevili (00:08) 8
anaraven (00:07) 7
sercihan (02:41) 161
sercihan (00:05) 5
damla.uz (00:49) 49
mkandemi (00:00) 0
gamzemer (00:43) 43
hilal_ca (00:45) 45
mkandemi (02:15) 135
ssohn199 (00:48) 48
mkandemi (00:00) 0
gizemgun (00:33) 33
kadeertu (00:04) 4
hilal_ca (01:19) 79
mkandemi (02:12) 132
kelifklc (01:27) 87
hilal_ca (00:09) 9
mkandemi (02:17) 137
berfinba (01:34) 94
kubrakhr (01:34) 94
dikbas.n (01:34) 94
sercihan (01:34) 94
kadeertu (01:41) 101
mkandemi (00:02) 2
alpaslan (01:44) 104
mkandemi (00:00) 0
mevlutge (01:43) 103
mevlutge (00:01) 1
mevlutge (01:44) 104
gizemgun (01:48) 108
kadir_mi (01:53) 113
mkandemi (00:07) 7
c_nrc_n (01:52) 112
gamzemer (01:14) 74
ssohn199 (01:12) 72
sercihan (00:26) 26
berkay_e (01:58) 118
mkandemi (02:16) 136
mkandemi (02:46) 166
mevlutge (18:33) 1113
mevlutge (01:31) 91
aysenurt (02:12) 132
aysenurt (02:47) 167
gamzemer (00:03) 3
begumsek (00:10) 10
gamzemer (00:14) 14
gizemgun (00:20) 20
gamzemer (00:18) 18
gizemgun (00:23) 23
ssohn199 (00:10) 10
kubrakhr (00:25) 25
dikbas.n (00:31) 31
gamzemer (00:14) 14
hilal_ca (00:30) 30
gizemgun (00:17) 17
ssohn199 (00:19) 19
buse.azm (00:40) 40
damla.uz (00:38) 38
buse.azm (00:10) 10
sercihan (00:39) 39
kadeertu (00:07) 7
mevlutge (01:44) 104
kadeertu (00:50) 50
kelifklc (05:51) 351
alpaslan (00:54) 54
kelifklc (05:57) 357
anaraven (00:06) 6
anaraven (00:00) 0
anaraven (01:23) 83
ssohn199 (01:27) 87
aayden (02:13) 133
c_nrc_n (00:38) 38
anaraven (01:02) 62
sercihan (00:46) 46
aayden (02:14) 134
anaraven (02:28) 148
aayden (00:06) 6
c_nrc_n (00:56) 56
c_nrc_n (00:00) 0
c_nrc_n (00:13) 13
anaraven (00:00) 0
anaraven (00:00) 0
anaraven (00:00) 0
anaraven (00:05) 5
anaraven (00:00) 0
anaraven (00:00) 0
sercihan (00:21) 21
sercihan (00:27) 27
c_nrc_n (00:11) 11
c_nrc_n (00:00) 0
c_nrc_n (00:49) 49
sercihan (00:00) 0
anaraven (00:03) 3
anaraven (00:00) 0
anaraven (00:00) 0
anaraven (00:00) 0
anaraven (00:00) 0
anaraven (00:00) 0
anaraven (00:07) 7
anaraven (00:00) 0
anaraven (00:00) 0
nicat990 (00:01) 1
mkandemi (00:00) 0
anaraven (00:04) 4
hilal_ca (00:18) 18
kubrakhr (00:05) 5
dikbas.n (00:36) 36
aysenurt (00:16) 16
dikbas.n (00:16) 16
mkandemi (02:17) 137
c_nrc_n (01:04) 64
mkandemi (02:12) 132
cansutun (00:18) 18
cansutun (00:18) 18
ssohn199 (01:25) 85
mkandemi (02:32) 152
kadeertu (01:33) 93
cansutun (00:14) 14
kadeertu (01:34) 94
mkandemi (02:36) 156
buse.azm (00:43) 43
aysenurt (01:38) 98
andres (03:56) 236
begumsek (00:53) 53
damla.uz (01:00) 60
mkandemi (02:25) 145
alpaslan (01:54) 114
hamednad (01:51) 111
alpaslan (00:01) 1
ssohn199 (01:51) 111
aysenurt (00:00) 0
mevlutge (00:17) 17
sercihan (01:55) 115
berfinba (01:55) 115
sercihan (00:01) 1
aysenurt (00:45) 45
mevlutge (01:22) 82
c_nrc_n (02:04) 124
kadir_mi (01:42) 102
kadir_mi (02:09) 129
berkay_e (02:06) 126
anaraven (00:12) 12
anaraven (00:00) 0
anaraven (00:00) 0
anaraven (00:01) 1
alpaslan (13:03) 783
alpaslan (00:30) 30
aysenurt (00:00) 0
aysenurt (00:49) 49
aysenurt (01:03) 63
aysenurt (00:20) 20
aysenurt (00:29) 29
aysenurt (00:31) 31
anaraven (00:00) 0
anaraven (00:18) 18
anaraven (00:00) 0
anaraven (00:00) 0
kadir_mi (10:23) 623
kadir_mi (01:03) 63
anaraven (00:14) 14
kadeertu (00:01) 1
cansutun (00:03) 3
kubrakhr (00:06) 6
anaraven (00:12) 12
anaraven (00:00) 0
anaraven (00:00) 0
gizemgun (00:17) 17
begumsek (00:19) 19
kadir_mi (00:19) 19
andres (00:23) 23
andres (00:28) 28
beyza_bh (00:28) 28
anaraven (00:18) 18
anaraven (00:01) 1
anaraven (00:00) 0
anaraven (00:00) 0
mevlutge (00:34) 34
hilal_ca (00:03) 3
beyza_bh (00:08) 8
mevlutge (00:06) 6
beyza_bh (00:16) 16
dikbas.n (00:48) 48
kubrakhr (00:38) 38
kadir_mi (00:47) 47
alpaslan (00:10) 10
aysenurt (00:49) 49
aysenurt (00:51) 51
kelifklc (01:30) 90
anaraven (00:28) 28
alpaslan (01:03) 63
aysenurt (00:03) 3
aysenurt (00:03) 3
aysenurt (00:01) 1
ssohn199 (08:36) 516
anaraven (01:44) 104
anaraven (00:20) 20
hamednad (00:00) 0
anaraven (00:03) 3
anaraven (00:00) 0
anaraven (00:21) 21
anaraven (00:20) 20

How many minutes lasted each connection?

In some cases last column gives may be (d+hh:mm). Use a regular expression to select only lines that match this format. Use the split() command to obtain hours and minutes. Print the first and last columns, and the total of minutes

gamzemer (1+00:03) 1443
aayden (3+23:44) 5744
esengul (3+23:43) 5743
ziyabay1 (1+02:49) 1609
ziyabay1 (1+02:38) 1598
hilal_ca (1+02:41) 1601
ecenaz.y (1+02:37) 1597
ssohn199 (1+02:42) 1602
ssohn199 (1+02:39) 1599
kadeertu (1+02:47) 1607

How many minutes lasted each connection?

In some cases last column gives may be (d+hh:mm). Use a regular expression to select only lines that match this format. Use the split() command to obtain hours and minutes. Print the first and last columns, and the total of minutes

awk '/\([0-9]+\+[0-9]{2}:[0-9]{2}\)/ {
    split($NF,a,/[:()+]/);
    print $1,$NF,a[4]+60*(a[3]+24*a[2])}' last.txt
gamzemer (1+00:03) 1443
aayden (3+23:44) 5744
esengul (3+23:43) 5743
ziyabay1 (1+02:49) 1609
ziyabay1 (1+02:38) 1598
hilal_ca (1+02:41) 1601
ecenaz.y (1+02:37) 1597
ssohn199 (1+02:42) 1602
ssohn199 (1+02:39) 1599
kadeertu (1+02:47) 1607
mevlutge (1+02:44) 1604
alpaslan (1+02:42) 1602
hilal_ca (3+05:18) 4638
cansutun (3+05:37) 4657
ziyabay1 (3+06:19) 4699
ziyabay1 (3+06:20) 4700
mevlutge (3+06:27) 4707
alpaslan (3+06:30) 4710
ssohn199 (1+02:42) 1602
ziyabay1 (1+02:36) 1596
ziyabay1 (1+02:39) 1599
gamzemer (1+02:29) 1589
beyza_bh (1+02:46) 1606
hilal_ca (1+02:46) 1606
hilal_ca (1+02:48) 1608
alpaslan (1+02:52) 1612
gamzemer (1+02:45) 1605
ssohn199 (1+02:45) 1605
mevlutge (1+02:48) 1608
kelifklc (1+02:45) 1605

Combine the last two awk commands into a single one

Ignore the lines that say gone or down

gamzemer (00:30) 30
anaraven (00:11) 11
fustunel (00:19) 19
ansevili (00:22) 22
aayden (00:26) 26
busrabal (01:11) 71
ansevili (01:03) 63
aayden (02:14) 134
edasmlgl (03:51) 231
anaraven (00:01) 1

Combine the last two awk commands into a single one

Ignore the lines that say gone or down

awk '/gone/ {next} /down/ {next} 
/\([0-9]+\+[0-9]{2}:[0-9]{2}\)/ {
    split($NF,a,/[:()+]/);
    print $1, $NF, a[4]+60*(a[3]+24*a[2])}
/\([0-9]{2}:[0-9]{2}\)/ {
    split($NF,a,/[:()]/);
    print $1,$NF,a[3]+60*a[2]}' last.txt
gamzemer (00:30) 30
anaraven (00:11) 11
fustunel (00:19) 19
ansevili (00:22) 22
aayden (00:26) 26
busrabal (01:11) 71
ansevili (01:03) 63
aayden (02:14) 134
edasmlgl (03:51) 231
anaraven (00:01) 1
ansevili (00:09) 9
edasmlgl (01:07) 67
anaraven (00:02) 2
anaraven (02:39) 159
busrabal (02:26) 146
fustunel (02:10) 130
aayden (02:35) 155
aayden (00:12) 12
aayden (00:00) 0
anaraven (01:39) 99
anaraven (00:21) 21
ssohn199 (01:54) 114
anaraven (01:36) 96
ssohn199 (17:04) 1024
ssohn199 (00:06) 6
gamzemer (01:19) 79
sercihan (01:25) 85
sercihan (00:22) 22
anaraven (00:02) 2
anaraven (00:00) 0
anaraven (00:05) 5
anaraven (00:00) 0
gizemgun (01:02) 62
gamzemer (1+00:03) 1443
gamzemer (01:16) 76
c_nrc_n (02:13) 133
ziyabay1 (09:51) 591
gamzemer (03:31) 211
gamzemer (20:13) 1213
mevlutge (00:05) 5
mevlutge (05:32) 332
aayden (00:49) 49
aayden (00:00) 0
aayden (00:10) 10
anaraven (02:12) 132
aayden (3+23:44) 5744
ansevili (01:11) 71
anaraven (01:20) 80
busrabal (01:09) 69
esengul (3+23:43) 5743
fustunel (01:23) 83
ansevili (00:08) 8
anaraven (00:07) 7
sercihan (02:41) 161
sercihan (00:05) 5
damla.uz (00:49) 49
mkandemi (00:00) 0
gamzemer (00:43) 43
hilal_ca (00:45) 45
mkandemi (02:15) 135
ssohn199 (00:48) 48
mkandemi (00:00) 0
gizemgun (00:33) 33
kadeertu (00:04) 4
hilal_ca (01:19) 79
mkandemi (02:12) 132
kelifklc (01:27) 87
hilal_ca (00:09) 9
mkandemi (02:17) 137
berfinba (01:34) 94
kubrakhr (01:34) 94
dikbas.n (01:34) 94
sercihan (01:34) 94
kadeertu (01:41) 101
mkandemi (00:02) 2
alpaslan (01:44) 104
mkandemi (00:00) 0
mevlutge (01:43) 103
mevlutge (00:01) 1
mevlutge (01:44) 104
gizemgun (01:48) 108
kadir_mi (01:53) 113
mkandemi (00:07) 7
c_nrc_n (01:52) 112
ziyabay1 (1+02:49) 1609
gamzemer (01:14) 74
ssohn199 (01:12) 72
sercihan (00:26) 26
berkay_e (01:58) 118
mkandemi (02:16) 136
mkandemi (02:46) 166
mevlutge (18:33) 1113
mevlutge (01:31) 91
aysenurt (02:12) 132
aysenurt (02:47) 167
gamzemer (00:03) 3
ziyabay1 (1+02:38) 1598
begumsek (00:10) 10
hilal_ca (1+02:41) 1601
ecenaz.y (1+02:37) 1597
gamzemer (00:14) 14
ssohn199 (1+02:42) 1602
gizemgun (00:20) 20
ssohn199 (1+02:39) 1599
gamzemer (00:18) 18
gizemgun (00:23) 23
ssohn199 (00:10) 10
kubrakhr (00:25) 25
dikbas.n (00:31) 31
gamzemer (00:14) 14
hilal_ca (00:30) 30
gizemgun (00:17) 17
ssohn199 (00:19) 19
buse.azm (00:40) 40
damla.uz (00:38) 38
kadeertu (1+02:47) 1607
buse.azm (00:10) 10
sercihan (00:39) 39
mevlutge (1+02:44) 1604
kadeertu (00:07) 7
mevlutge (01:44) 104
kadeertu (00:50) 50
kelifklc (05:51) 351
alpaslan (1+02:42) 1602
alpaslan (00:54) 54
kelifklc (05:57) 357
anaraven (00:06) 6
anaraven (00:00) 0
anaraven (01:23) 83
ssohn199 (01:27) 87
aayden (02:13) 133
c_nrc_n (00:38) 38
anaraven (01:02) 62
sercihan (00:46) 46
aayden (02:14) 134
anaraven (02:28) 148
aayden (00:06) 6
c_nrc_n (00:56) 56
c_nrc_n (00:00) 0
c_nrc_n (00:13) 13
anaraven (00:00) 0
anaraven (00:00) 0
anaraven (00:00) 0
anaraven (00:05) 5
anaraven (00:00) 0
anaraven (00:00) 0
sercihan (00:21) 21
sercihan (00:27) 27
c_nrc_n (00:11) 11
c_nrc_n (00:00) 0
c_nrc_n (00:49) 49
sercihan (00:00) 0
anaraven (00:03) 3
anaraven (00:00) 0
anaraven (00:00) 0
anaraven (00:00) 0
anaraven (00:00) 0
anaraven (00:00) 0
anaraven (00:07) 7
anaraven (00:00) 0
anaraven (00:00) 0
nicat990 (00:01) 1
mkandemi (00:00) 0
anaraven (00:04) 4
hilal_ca (00:18) 18
kubrakhr (00:05) 5
dikbas.n (00:36) 36
aysenurt (00:16) 16
dikbas.n (00:16) 16
mkandemi (02:17) 137
c_nrc_n (01:04) 64
mkandemi (02:12) 132
cansutun (00:18) 18
cansutun (00:18) 18
ssohn199 (01:25) 85
mkandemi (02:32) 152
kadeertu (01:33) 93
cansutun (00:14) 14
kadeertu (01:34) 94
mkandemi (02:36) 156
buse.azm (00:43) 43
aysenurt (01:38) 98
andres (03:56) 236
begumsek (00:53) 53
damla.uz (01:00) 60
mkandemi (02:25) 145
alpaslan (01:54) 114
hamednad (01:51) 111
alpaslan (00:01) 1
ssohn199 (01:51) 111
aysenurt (00:00) 0
mevlutge (00:17) 17
sercihan (01:55) 115
berfinba (01:55) 115
sercihan (00:01) 1
aysenurt (00:45) 45
mevlutge (01:22) 82
c_nrc_n (02:04) 124
kadir_mi (01:42) 102
kadir_mi (02:09) 129
berkay_e (02:06) 126
anaraven (00:12) 12
anaraven (00:00) 0
anaraven (00:00) 0
anaraven (00:01) 1
alpaslan (13:03) 783
alpaslan (00:30) 30
aysenurt (00:00) 0
aysenurt (00:49) 49
aysenurt (01:03) 63
aysenurt (00:20) 20
aysenurt (00:29) 29
aysenurt (00:31) 31
anaraven (00:00) 0
anaraven (00:18) 18
anaraven (00:00) 0
anaraven (00:00) 0
kadir_mi (10:23) 623
kadir_mi (01:03) 63
anaraven (00:14) 14
kadeertu (00:01) 1
cansutun (00:03) 3
kubrakhr (00:06) 6
anaraven (00:12) 12
anaraven (00:00) 0
anaraven (00:00) 0
ssohn199 (1+02:42) 1602
gizemgun (00:17) 17
begumsek (00:19) 19
ziyabay1 (1+02:36) 1596
kadir_mi (00:19) 19
andres (00:23) 23
ziyabay1 (1+02:39) 1599
gamzemer (1+02:29) 1589
andres (00:28) 28
beyza_bh (00:28) 28
anaraven (00:18) 18
anaraven (00:01) 1
anaraven (00:00) 0
anaraven (00:00) 0
beyza_bh (1+02:46) 1606
hilal_ca (1+02:46) 1606
hilal_ca (1+02:48) 1608
mevlutge (00:34) 34
hilal_ca (00:03) 3
beyza_bh (00:08) 8
alpaslan (1+02:52) 1612
mevlutge (00:06) 6
gamzemer (1+02:45) 1605
ssohn199 (1+02:45) 1605
beyza_bh (00:16) 16
dikbas.n (00:48) 48
mevlutge (1+02:48) 1608
kubrakhr (00:38) 38
kadir_mi (00:47) 47
kelifklc (1+02:45) 1605
alpaslan (00:10) 10
aysenurt (00:49) 49
aysenurt (00:51) 51
kelifklc (01:30) 90
anaraven (00:28) 28
alpaslan (01:03) 63
aysenurt (00:03) 3
aysenurt (00:03) 3
aysenurt (00:01) 1
ssohn199 (08:36) 516
anaraven (01:44) 104
anaraven (00:20) 20
hamednad (00:00) 0
anaraven (00:03) 3
anaraven (00:00) 0
anaraven (00:21) 21
anaraven (00:20) 20

Combine the last answer with the second one

Show how many minutes each person was connected in the last month

buse.azm 93
fustunel 232
anaraven 1205
berkay_e 244
kadir_mi 1096
kelifklc 2490
kadeertu 1957
alpaslan 4373
hilal_ca 4999
busrabal 286

Combine the last answer with the second one

Show how many minutes each person was connected in the last month

awk '/gone/ {next} /down/ {next} 
/\([0-9]{2}:[0-9]{2}\)/ {
    split($NF,a,/[:()]/);
    n[$1] += a[3]+60*a[2]}
/\([0-9]+\+[0-9]{2}:[0-9]{2}\)/ {
    split($NF,a,/[:()+]/); 
    n[$1] += a[4]+60*(a[3]+24*a[2])}
END {for(u in n) {print u, n[u]}}' last.txt
buse.azm 93
fustunel 232
anaraven 1205
berkay_e 244
kadir_mi 1096
kelifklc 2490
kadeertu 1957
alpaslan 4373
hilal_ca 4999
busrabal 286
ziyabay1 6993
ansevili 173
mkandemi 1437
aayden 6403
aysenurt 757
gizemgun 280
andres 287
esengul 5743
edasmlgl 298
gamzemer 6412
beyza_bh 1658
c_nrc_n 600
ecenaz.y 1597
dikbas.n 225
kubrakhr 168
berfinba 209
mevlutge 5204
begumsek 82
sercihan 642
hamednad 111
cansutun 53
nicat990 1
damla.uz 147
ssohn199 8500

Other resources

Google awk turkce

Next week

  • Arrive early
  • Test your computer early
  • You can bring your own computer
  • All work must be done on the server

Do all the quizzes

I wish you success