#!/usr/bin/awk -f # Format der Eingabedatei: # Bei Beginnt jeweils eine neue Tabellenzeile, also ein Student. # Nach jedem Studenten ist ein newline enthalten. # trennt die Spalten. # Spalte 1 enthält den Namen, dann kommen jeweils zwei Spalten pro # Woche, eine für Anwesenheit und eine für Hausaufgabe. # Nach der 4. und 8. Wochen steht erneut eine Spalte mit Namen. BEGIN { FS = "" } // { # Anwesenheit: # compute the right column in x jump = int(woche/4) ; fraction = woche / 4 - jump ; if (fraction > 0) { jump = jump + 1; } x = 2 * woche + jump; # now get the column as a string feld = $x # convert the string to array laenge_feldarray = split(feld, feldarray, " "); # search for the SELECTED keyword for (i = 1; i <= laenge_feldarray; i++) { if (feldarray[i] == "SELECTED") { delete feldarray[i]; } else { if (match(feldarray[i], ">j<")) { feldarray[i] = "SELECTED " feldarray[i]; } feldarray[i] = feldarray[i] " "; } } line = ""; for (j = 1; NF >= j; j++) { if (j == x) { for (i = 1; i <= laenge_feldarray; i++) { line = line feldarray[i]; } line = line; } else { line = line $j; } if (j < NF) line = line ""; } print line; } $0 !~ // { print $0 }