From the command line, how can I merge multiple .ics calendar files in to one .ics calendar file?
2 Answers
I used this script:
echo "BEGIN:VCALENDAR" >> merge;
for file in *.ics; do
cat "$file" | sed -e '$d' $1 | sed -e '1,/VEVENT/{/VEVENT/p;d;}' $2 >> merge;
done
mv merge merge.ics
echo "END:VCALENDAR" >> merge.ics;
-
This leads to the sed error
sed: 1: "1,/VEVENT/{/VEVENT/p;d} ": extra characters at the end of d commandMundi– Mundi2021-09-01 16:01:45 +00:00Commented Sep 1, 2021 at 16:01 -
Are you on Linux? As I understood sed has problems on BSD and Mac systems. If so - try "sed -i''.Danila Kiselev– Danila Kiselev2021-09-03 22:59:17 +00:00Commented Sep 3, 2021 at 22:59
-
Correct, I am on Mac. Now the error is
sed: -I or -i cannot be used with stdin.Mundi– Mundi2021-09-05 21:26:25 +00:00Commented Sep 5, 2021 at 21:26 -
1@PatrikNovák : The fix for your script is only one additional semicolon. Because it's such a small change, the system won't let me edit it for you. Here's what I was trying to add for the EDIT summary: The complaints about the script failing were due to a missing semicolon after "d" within the second sed command. The code for the second sed command can be easily written as
sed -e '1,/VEVENT/{/VEVENT/p;d;}' $2I tested and confirmed it works on both Mac and Linux. Cheers! :)JBMcClure– JBMcClure2022-02-05 11:33:42 +00:00Commented Feb 5, 2022 at 11:33 -
2Concatenating
.icsfiles (esp. when just extracting theVEVENTblocks) is a partial solution, especially if the source.icsfiles are invitations (text/calendarattachments).METHOD:CANCELwill not be handled, so the resulting calendar will contain events that had been canceled.UIDdeduplication is not done, so it will have duplicate events unless the consuming calendar program deduplicates them. Most importantly, eachVCALENDARcan have its ownVTIMEZONEinformation, which is discarded here completely. Beware.Vladimir Panteleev– Vladimir Panteleev2023-05-22 12:48:04 +00:00Commented May 22, 2023 at 12:48
I'm using the following:
find . -name '*.ics' -print0 | xargs -0 cat | grep -v -e "BEGIN:VCALENDAR" -e "END:VCALENDAR"
Later, you need to insert the "BEGIN:VCALENDAR" and "END:VCALENDAR" once into the file.
Hope this helps.
G