Line separated value -> iCalendar 변환 스크립트

Sun Mar 31, 2024
1 minute to read

줄 단위로 나눈 데이터를 SUMMARY에 넣어 iCalendar 형식으로 변환해준다.

 1#!/bin/bash
 2
 3# Check if the correct number of arguments is provided
 4if [ "$#" -ne 2 ]; then
 5    echo "Usage: $0 input_file output_file"
 6    exit 1
 7fi
 8
 9input_file=$1
10output_file=$2
11
12# Check if the input file exists
13if [ ! -e "$input_file" ]; then
14    echo "Error: Input file not exists."
15    exit 1
16fi
17
18# Start building the iCalendar file
19echo "BEGIN:VCALENDAR" > "$output_file"
20echo "VERSION:2.0" >> "$output_file"
21
22# Read each line from the input file
23while IFS= read -r summary; do
24    # Generate dummy dates (adjust as needed)
25    dummy_due_date="20230101T000000Z"
26
27    echo "BEGIN:VTODO" >> "$output_file"
28    echo "SUMMARY:$summary" >> "$output_file"
29    echo "DUE:$dummy_due_date" >> "$output_file"
30    echo "STATUS:NEEDS-ACTION" >> "$output_file"
31    echo "END:VTODO" >> "$output_file"
32done < "$input_file"
33
34# Close the iCalendar file
35echo "END:VCALENDAR" >> "$output_file"
36
37echo "Output: $output_file"