rev. N21
Esmaspäev 03.10.2022 | REGEX="^(Esmaspäev|Teisipäev|Kolmapäev|Neljapäev|Reede|Laupäev|Pühapäev) ([0-9]{2}\.){2}[0-9]{4}$"
13:25-14:10 | REGEX="^([0-9]{2}:[0-9]{2}-?){2}$"
Infotund | pcregrep -M '\nÕpe' | grep -v Õpe | grep -P --color=always '.+'
Õpetaja Maret Vaher | REGEX="^Õpetaja .*$"
Ruum A201 | REGEX="^Ruum [A-Z][0-9]{3}$"
Õpperühm KIT-22V | REGEX="^Õpperühm [A-Z0-9-]+$"
cat tt01 | grep -P --color=always "$REGEX"
https://stackoverflow.com/questions/3717772/regex-grep-for-multi-line-search-needed
https://stackoverflow.com/questions/152708/how-can-i-search-for-a-multiline-pattern-in-a-file
tt01.txt
is created by copy-paste from bootstrap narrowed timetable available on www.tptlive.ee -> Tunniplaan
stage1.awk
BEGIN { ORS="" }
/^((Esmas|Teisi|Kolma|Nelja|Lau|Püha)päev|Reede) ([0-9.]+)$/{
f=$0
}
/^([0-9]{2}:[0-9]{2}-?){2}$/ { print "{\n" }
/^([0-9]{2}:[0-9]{2}-?){2}$/,/^Õpetaja .*$/ {
if ($0 ~ "^Õpe") {
if ($0 ~ "Nelus") print ", Linux\"\n"; else print "\"\n"
print " \"TEACHER\": \"" $2, $3, $4, "\"\n"
}
else if ($0 ~ "^[0-9]") print " \"DATETIME\":\"" f $0, "\"\n"
else print " \"SUBJECT\": \"" $0
}
/^Ruum/ { print " \"ROOM\": \"" $2, "\"\n" }
/^Õpperühm/ { print " \"TEAM\": \"" $2, "\"\n},\n" }
Output:
$ cat tt01.txt | awk -f stage1.awk
{
"DATETIME":"Esmaspäev 03.10.202213:25-14:10 "
"SUBJECT": "Infotund"
"TEACHER": "Maret Vaher "
"ROOM": "A201 "
"TEAM": "KIT-22V "
},
{
"DATETIME":"Esmaspäev 03.10.202214:20-15:05 "
"SUBJECT": "Elektrotehnika"
"TEACHER": "Natalia Popova "
"ROOM": "A310 "
"TEAM": "KIT-22V "
},
{
"DATETIME":"Esmaspäev 03.10.202215:15-16:00 "
"SUBJECT": "Elektrotehnika"
"TEACHER": "Natalia Popova "
"ROOM": "A310 "
"TEAM": "KIT-22V "
},
..
#! /bin/bash
echo "so far Linux total $(sh -c 'cat tt02.json | grep Linux | wc -l')"
echo "so far Linux Install $(sh -c 'cat tt02.json | grep Linux | grep Pai | wc -l')"
echo "so far Linux Use $(sh -c 'cat tt02.json | grep Linux | grep Kasu | wc -l')"
echo "so far Linux Daemons $(sh -c 'cat tt02.json | grep Linux | grep Teen | wc -l')"
echo "so far Linux Diagnostics $(sh -c 'cat tt02.json | grep Linux | grep Diag | wc -l')"
echo "so far Discrete Math $(sh -c 'cat tt02.json | grep Linux | grep IOT | wc -l')"
output
so far Linux total 48
so far Linux Install 12
so far Linux Use 12
so far Linux Daemons 12
so far Linux Diagnostics 8
so far Discrete Math 4
Different queries: