3

From the command line, how can I merge multiple .ics calendar files in to one .ics calendar file?

1 Answer 1

3

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;
6
  • This leads to the sed error sed: 1: "1,/VEVENT/{/VEVENT/p;d} ": extra characters at the end of d command
    – Mundi
    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''. 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
    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;}' $2 I tested and confirmed it works on both Mac and Linux. Cheers! :)
    – JBMcClure
    Feb 5, 2022 at 11:33
  • 2
    Concatenating .ics files (esp. when just extracting the VEVENT blocks) is a partial solution, especially if the source .ics files are invitations (text/calendar attachments). METHOD:CANCEL will not be handled, so the resulting calendar will contain events that had been canceled. UID deduplication is not done, so it will have duplicate events unless the consuming calendar program deduplicates them. Most importantly, each VCALENDAR can have its own VTIMEZONE information, which is discarded here completely. Beware. May 22, 2023 at 12:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .