However, I've been unable to find a way to replace the last two digits to 00 and write it directly to the files. Apparently sed '/00$/!s/..$/00/' does some magic but I don't understand the exact syntax and it also doesn't write it to the files!
@Subbeh: I've been running all four variations without an error but the date/time string stays unchanged - I need to do more testing later as I assume it's still the ^M line ending that breaks it..
find . -type f -iname *.ics -exec sed -i "" -e '/^DT\(START\|END\)/s/[0-9][0-9]$/00/' -e 's/\r//' {} \;
find . -type f -iname *.ics -exec sed -i "" -e '/^DT\(START\|END\)/s/[0-9][0-9]$/00/' -e 's/^M//' {} \;
find . -type f -iname *.ics -exec sed -i "" '/^DT\(START\|END\)/s/[0-9][0-9]$/00/;s/\r//' {} \;
find . -type f -iname *.ics -exec sed -i "" '/^DT\(START\|END\)/s/[0-9][0-9]$/00/;s/^M//' {} \;
@Scrutinizer: The loop also works when I remove .bak:
for file in ~/Library/Calendars/*.calendar/Events/*.ics
do
[ -f "$file" ] || continue
sed -i "" -e '/^DTSTART/ba' -e'/^DTEND/ba' -e 'p;d' -e :a -e 's/..\(.\)$/00\1/' "$file"
done
The code is for BSD sed which is used on OSX. You can use it without .bak , but this is what the man page says:
-i extension
Edit files in-place, saving backups with the specified extension. If a zero-length extension is given, no backup will be
saved. It is not recommended to give a zero-length extension when in-place editing files, as you risk corruption or partial
content in situations where disk space is exhausted, etc.
The input should be a file that ends in '\r\n' and the output is also in this format...