#! /usr/bin/gawk -f # Last edited on 2013-05-29 23:29:40 by stolfilocal BEGIN \ { # Extracts from the log file of one of Ghislain's EEG experiments # the sequence of types ("Bio" or "nonBio") of the runs. state = 0; # Before a run. type = "??"; # Type of current run. abort = -1; } (abort >= 0) { exit abort; } # Make sure that there are no funny characters: /[\011\015]/ \ { gsub(/[\011\015]/, " ", $0); } # Ignore blank lines: /^[ ]*$/ \ { next; } # Ignore uninteresting lines: /^(Scenario|Logfile|Trial|[0-9]+[ ]+Nothing|Event)/ \ { next; } # Each run seems to start with "Picture": /^Picture/ \ { if (state == 0) { state = 1; next; } else { data_error(("expecting 'Picture'")); } } # Each run then has four "Nothing" lines: /^Nothing/ \ { rt = $2; if (state == 1) { if (rt == "pulso") { data_error(("expecting 'Nothing {type}', got 'Nothing pulso'")); } type = rt; print type; state = 2; next; } else if ((state == 2) || (state == 3)) { if (rt != "pulso") { data_error(("expecting 'Nothing pulso', got 'Nothing " rt "'")); } state++; next; } else if (state == 4) { # End of run if (type != rt) { data_error(("types do not match '" type "' '" rt "'")); } state = 0; type = "??"; next; } else { data_error(("unexpected 'Nothing'")); } } END \ { if (abort >= 0) { exit abort; } # File should end with a "Picture": if (state != 1) { data_error(("unexpected EOF in state " state)); } } function data_error(msg) { printf "%s:%d: %s\n", FILENAME, FNR, msg > "/dev/stderr"; printf " [%s]\n", $0 > "/dev/stderr"; abort = 1; exit abort; }