I'm trying to replace VEVENT to VTODO entries in an .ics file if it matches current date on another line (it was exported incorrectly):
BEGIN:VCALENDAR
BEGIN:VEVENT
DTSTART:20220340T140000
END:VEVENT
BEGIN:VEVENT
DTSTART:20230620T193700
END:VEVENT
BEGIN:VEVENT
DTSTART:20210210T193800
END:VEVENT
END:VCALENDAR
The second VEVENT entry has current time so it should become:
BEGIN:VTODO
DTSTART:20230620T193700
END:VTODO
There are more entries between BEGIN:VEVENT and END:VEVENT lines, I've redacted them for clarity.
I've tried this with sed, but the ranges pick the first occurrence of VEVENT in the entire file, not first occurrence after (or before) the matched pattern, so it replaces all of them.
sed -i "/BEGIN:VEVENT/,/DTSTART:$(date +%Y%m%dT%H%M)/{s/VEVENT/VTODO/}" org.ics
I was trying to adapt it to another question here, which I thought was relevant: Find a string and replace another string after the first is found
sed -n "/DTSTART:$(date +%Y%m%dT%H%M)/,${/END:VEVENT/{x//{x b}g s/VEVENT/VTODO/}}" org.ics
but it didn't work at all:
sed: -e expression #1, char 25: unexpected ,'`
