#!/bin/sh

DATE=$(date +%s)
WD=$(pwd)

INPUT=$1
SOURCE="/tmp/irssi-log-cleaner_source_$DATE"
DEST="/tmp/irssi-log-cleaner_dest_$DATE"
OUTPUT="$1.trn"

cp $INPUT $SOURCE

# remove whole useless lines with grep
# * log messages
# * service messages (joins, parts and similar)
# * bot actions ("saezz" in this case)
# * bot commands invocation (with !)
cat $SOURCE | grep -v '^\-\-\-' | grep -E -v '[0-9:\-]+ \-\!\-' | grep -E -v '[0-9:\-]+ +\* saezz*' | grep -v '<[^>]*> \!' > $DEST
cp $DEST $SOURCE

# remove useless parts with sed
# * timestamp/nick at line beginning
# * stimestamp/* in front of the real sentence (CTCP actions)
cat $SOURCE | sed -r -e 's/^[0-9:\-]+ <[^>]*> //g' -e 's/^[0-9:\-]+ +\* [^ ]* //g' > $DEST
cp $DEST $SOURCE

cp $DEST $OUTPUT

