tempdir=$(readlink -f "$tempdir")
trap "/bin/rm -f \"$tempdir\"/*.ics; rmdir \"$tempdir\"" QUIT INT EXIT
-for ics in "$@"; do
- bevents=($(grep -n BEGIN:VEVENT "$file" | cut -d: -f1))
- eevents=($(grep -n END:VEVENT "$file" | cut -d: -f1))
+for file in "$@"; do
+ bevents=($(grep -hn BEGIN:VEVENT "$file" | awk -F: '{print $1}'))
+ eevents=($(grep -hn END:VEVENT "$file" | awk -F: '{print $1}'))
ehead=${bevents[0]}
let "ehead -= 1"
- bfoot=$(wc -l < $file)
+ bfoot=$(wc -l "$file")
let "bfoot -= ${eevents[-1]}"
for (( i=0; i < ${#bevents[@]}; i++)); do
- head -n $ehead "$file" > "$file"-$i.ics
- sed -n ${bevents[$i]},${eevents[$i]}p "$file" >> "$file"-$i.ics
- tail -n $bfoot "$file" >> "$file"-$i.ics
+ head -n $ehead "$file" > "$file-$i.ics";
+ sed -n ${bevents[$i]},${eevents[$i]}p "$file" >> "$file-$i.ics";
+ tail -n $bfoot "$file" >> "$file-$i.ics";
done
done