adding strip_ics_alarms
This commit is contained in:
parent
8fdc0ec7c1
commit
7e6555860e
1 changed files with 70 additions and 0 deletions
70
shell/strip_ics_alarms.sh
Executable file
70
shell/strip_ics_alarms.sh
Executable file
|
|
@ -0,0 +1,70 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Given an ICS input file, write a new ICS output file with all the
|
||||
# alarms stripped out (BEGIN:VALARM -> END:VALARM)
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
if [ ! -r "$1" ]; then
|
||||
echo "Cannot read input file $1, exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
INFILE=$1
|
||||
OUTFILE="${INFILE}.stripped"
|
||||
|
||||
# create/truncate it so we can use >> later
|
||||
: > "${OUTFILE}"
|
||||
|
||||
VERBOSE=1
|
||||
READLINES=0
|
||||
WROTELINES=0
|
||||
EVENTCOUNT=0
|
||||
ALARMCOUNT=0
|
||||
GOTALARM=0
|
||||
|
||||
if [ ${VERBOSE} ]; then
|
||||
echo -n "Working"
|
||||
fi
|
||||
|
||||
# preserve whitespace, don't interpret escapes
|
||||
# shellcheck disable=SC2004
|
||||
while IFS=$'\n' read -r vline; do
|
||||
READLINES=$(($READLINES+1))
|
||||
if [ ${VERBOSE} ]; then
|
||||
if [ $(($READLINES%100)) -eq 0 ]; then
|
||||
echo -n "."
|
||||
fi
|
||||
fi
|
||||
# use substring matching to avoid possible '\r' and '^M' on lines
|
||||
if [ "${vline:0:12}" == "BEGIN:VEVENT" ]; then
|
||||
EVENTCOUNT=$(($EVENTCOUNT+1))
|
||||
fi
|
||||
if [ ${GOTALARM} -ne 1 ]; then
|
||||
if [ "${vline:0:12}" != "BEGIN:VALARM" ]; then
|
||||
# don't interpret escapes while writing
|
||||
echo -E "${vline}" >> "${OUTFILE}"
|
||||
WROTELINES=$(($WROTELINES+1))
|
||||
continue
|
||||
else
|
||||
GOTALARM=1
|
||||
continue
|
||||
fi
|
||||
else
|
||||
if [ "${vline:0:10}" == "END:VALARM" ]; then
|
||||
GOTALARM=0
|
||||
ALARMCOUNT=$(($ALARMCOUNT+1))
|
||||
fi
|
||||
continue
|
||||
fi
|
||||
done < "${INFILE}"
|
||||
|
||||
if [ ${VERBOSE} ]; then
|
||||
echo "done."
|
||||
echo "Read ${READLINES} lines"
|
||||
echo "Wrote ${WROTELINES} lines"
|
||||
echo "Found ${EVENTCOUNT} events"
|
||||
echo "Stripped ${ALARMCOUNT} alarms"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue