From: Gustav Eek Date: Sat, 24 Oct 2020 08:00:49 +0000 (+0200) Subject: [event-participant] Refactor management of expressions X-Git-Url: https://git.g-eek.se/?a=commitdiff_plain;h=70615bb2ce3da8d608d4026f387bf4c2e1d7986a;p=users%2Fgustav%2Fscripts.git [event-participant] Refactor management of expressions There was dual styles of expression usage. With this change all expressions are inline for simplicity. Also handling of command line arguments is slight updated. Also some navigatory comments are added. --- diff --git a/event-participant b/event-participant index 6c7664c..aee33cb 100755 --- a/event-participant +++ b/event-participant @@ -1,16 +1,9 @@ #!/usr/bin/env bash -EVENT="$1" CACHE="$HOME/.cache/${0##*/}/events.csv" HEADER="participant,date_att,date_cancel" -EXPR=" -1,/^$/ { - /^From:\|^Date:/ { - s/^[a-zA-Z]*: *\(.*\)$/\1/ - p - } -} -" + +arg_event="$1" if [ -f "$CACHE" ]; then event=$(tail -1 "$CACHE") @@ -18,8 +11,8 @@ else mkdir -p $(dirname "$CACHE") echo -n "" > "$CACHE" fi -if [ -n "$EVENT" -a "$EVENT" != "$event" ]; then - event="$EVENT" +if [ -n "$arg_event" -a "$arg_event" != "$event" ]; then + event="$arg_event" echo "$event" >> "$CACHE" fi if [ -z "$event" ]; then @@ -27,8 +20,9 @@ if [ -z "$event" ]; then exit 1 fi -#info=$(cat | sed -n -e "$EXPR" | tr '\n' '|') -info=$(cat | grep '^From:\|^Date:' | tr '\n' ':') +# Add info, sorted by date and uniq + +info=$(cat | grep "^From:\|^Date:" | tr '\n' ':') [[ "$info" =~ (From: )([^:]*) ]] participant="${BASH_REMATCH[2]}" @@ -36,6 +30,9 @@ participant="${BASH_REMATCH[2]}" date=$(date -I -d "${BASH_REMATCH[2]}") echo "${participant},${date}" | tee -a "$event" + +# Print summary + n_t=$(cat "$event" | grep -v "$HEADER"| cut -d, -f2 | grep -v '^$' | wc -l) n_c=$(cat "$event" | grep -v "$HEADER"| cut -d, -f3 | grep -v '^$' | wc -l) n_p=$(( $n_t - $n_c ))