我正在编写一个脚本来将我的 git 日志转换为谷歌日历格式。但是当我检查 calendar.txt 文件时,它只有初始标题行。
我在 sublime 中手动使用了这个正则表达式,它工作得很好。所以我的 bash 语法一定有问题。
#! /bin/bash
# add git log
git log --date=iso --pretty=format:"%ad%x09%s" > calendartmp.txt
# add header line to beginning of file
echo "Start Date,Start Time,Subject" > calendar.txt
#parse line by line into correct format
# "\d\d(\d\d)-(\d\d)-(\d\d) ([\d+\:]+) .*\t(.*)" -> "$2/$3/$1,$4,$5"
while read p; do
[[ $p =~ \d\d(\d\d)\-(\d\d)\-(\d\d)\ (\d\d\:\d\d\:\d\d).*\t(.*) ]] && echo "${BASH_REMATCH[2]}/${BASH_REMATCH[3]}/${BASH_REMATCH[1]},${BASH_REMATCH[4]},${BASH_REMATCH[5]}" >> calendar.txt
done < calendartmp.txt
#delete temp file
rm calendartmp.txt