Skip to content

Instantly share code, notes, and snippets.

@HappyStinson
Last active January 8, 2026 18:33
Show Gist options
  • Select an option

  • Save HappyStinson/e8e39bfa8405993b2251eaa73e47af70 to your computer and use it in GitHub Desktop.

Select an option

Save HappyStinson/e8e39bfa8405993b2251eaa73e47af70 to your computer and use it in GitHub Desktop.
Combine ICS Files. This shell script combines multiple .ics calendar files into a single .ics file. It checks for existing .ics files in the directory, extracts the events from each file, and compiles them into one output file named combined.ics. Features: Automatically detects and processes all .ics files in the current directory. Retains the h…
#!/bin/bash
# Output file where all .ics files will be combined
OUTPUT_FILE="combined.ics"
# Check if any .ics files exist in the directory
if ls *.ics 1> /dev/null 2>&1; then
echo "Combining all .ics files into $OUTPUT_FILE..."
# Start with an empty output file (or create a new one)
> "$OUTPUT_FILE"
# Add the header from the first .ics file up to (but not including) the first BEGIN:VEVENT
first_file=$(ls *.ics | grep -v "$OUTPUT_FILE" | head -n 1)
sed -n '1,/BEGIN:VEVENT/ p' "$first_file" | grep -v "BEGIN:VEVENT" >> "$OUTPUT_FILE"
# Loop through each .ics file (excluding the combined output file) and combine them
for file in *.ics; do
# Exclude the output file from being processed
if [ "$file" != "$OUTPUT_FILE" ]; then
echo "Processing $file"
# Extract the events only
sed -n '/BEGIN:VEVENT/,/END:VEVENT/p' "$file" >> "$OUTPUT_FILE"
fi
done
# Add the footer lines at the end of the combined file
echo "END:VCALENDAR" >> "$OUTPUT_FILE"
echo "All .ics files combined successfully into $OUTPUT_FILE"
else
echo "No .ics files found in the directory."
fi
@NBA2K1
Copy link

NBA2K1 commented Dec 23, 2025

Thank you!
Worked beautifully!

@HappyStinson
Copy link
Author

Thank you! Worked beautifully!

You are welcome. Merry Christmas!

@skout23
Copy link

skout23 commented Jan 7, 2026

I used this to combine a bunch of random calendar/ICS to populate a daily scribe calendar. Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment