-
Notifications
You must be signed in to change notification settings - Fork 0
/
vevent_dump
executable file
·45 lines (39 loc) · 2.55 KB
/
vevent_dump
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /bin/sh
# Create somewhat readable output from ICS (or similar) files.
# Copyright (C) 2017-2023 Erik Auerswald <[email protected]>
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.
# Version 2023-06-04-01
process_event_data() {
test $# -eq 0 && FILE='-' NAME='standard input' || FILE=$1 NAME=$1
printf -- '========[ %s ]========\n' "$NAME"
sed -n '/BEGIN:VEVENT/,/END:VEVENT/p' "$FILE" \
| sed -e '/BEGIN:VALARM/,/END:VALARM/d' \
-e '/^[[:space:]]*X-MS-OLK/d' \
-e 's/\r$//' \
| sed ':RN;$!N;s/\n[[:space:]]//;tRN;P;D' \
| sed -nE \
-e '/ORGANIZER/s/^.*CN="?([^":;]+)"?.*:[Mm][Aa][Ii][Ll][Tt][Oo]:([^[:space:]]+).*$/Organizer: \1 <\2>/p' \
-e '/ATTENDEE/s/^.*CN="?([^":;]+)"?.*:[Mm][Aa][Ii][Ll][Tt][Oo]:([^[:space:]]+).*$/Attendee: \1 <\2>/p' \
-e '/SUMMARY/s/^[^:]*:(.*)$/Summary: \1/p' \
-e '/DTSTART;TZID=/s/^.*TZID=([^:]+):([[:digit:]]{4})([[:digit:]]{2})([[:digit:]]{2})T([[:digit:]]{2})([[:digit:]]{2})([[:digit:]]{2}).*$/Start: \4.\3.\2 at \5:\6:\7 (\1)/p' \
-e '/DTSTART/s/^.*:([[:digit:]]{4})([[:digit:]]{2})([[:digit:]]{2})T([[:digit:]]{2})([[:digit:]]{2})([[:digit:]]{2})([A-Z]{1,4}).*$/Start: \3.\2.\1 at \4:\5:\6 (\7)/p' \
-e '/DTSTART/s/^.*:([[:digit:]]{4})([[:digit:]]{2})([[:digit:]]{2})T([[:digit:]]{2})([[:digit:]]{2})([[:digit:]]{2}).*$/Start: \3.\2.\1 at \4:\5:\6/p' \
-e '/DTSTART;VALUE=DATE:/s/^.*:([[:digit:]]{4})([[:digit:]]{2})([[:digit:]]{2})/Start: \3.\2.\1/p' \
-e '/DTEND;TZID=/s/^.*TZID=([^:]+):([[:digit:]]{4})([[:digit:]]{2})([[:digit:]]{2})T([[:digit:]]{2})([[:digit:]]{2})([[:digit:]]{2}).*$/End: \4.\3.\2 at \5:\6:\7 (\1)/p' \
-e '/DTEND/s/^.*:([[:digit:]]{4})([[:digit:]]{2})([[:digit:]]{2})T([[:digit:]]{2})([[:digit:]]{2})([[:digit:]]{2})([A-Z]{1,4}).*$/End: \3.\2.\1 at \4:\5:\6 (\7)/p' \
-e '/DTEND/s/^.*:([[:digit:]]{4})([[:digit:]]{2})([[:digit:]]{2})T([[:digit:]]{2})([[:digit:]]{2})([[:digit:]]{2}).*$/End: \3.\2.\1 at \4:\5:\6/p' \
-e '/DTEND;VALUE=DATE:/s/^.*:([[:digit:]]{4})([[:digit:]]{2})([[:digit:]]{2})/End: \3.\2.\1/p' \
-e '/DESCRIPTION/s/^[^:]*:(.*)$/----=[ start description ]=----\n\1\n-----=[ end description ]=-----/p' \
-e '/LOCATION/s/^[^:]*:(.*)$/Location: \1/p' \
| sed 's/\\,/,/g;s/\\n/\n/g'
}
if test $# -eq 0; then
process_event_data
else
for F in "$@"; do
process_event_data "$F"
done
fi