#!/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")
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
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]}"
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 ))