forked from qiandaoniaoren/jd-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv.sh
30 lines (25 loc) · 964 Bytes
/
csv.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env bash
## 判断环境
ShellDir=${JD_DIR:-$(cd $(dirname $0); pwd)}
LogDir=${ShellDir}/log
Income=${LogDir}/bean_income.csv
Outlay=${LogDir}/bean_outlay.csv
Total=${LogDir}/bean_total.csv
## 执行
cd ${LogDir}/jd_bean_change
for log in $(ls); do
LogDate=$(echo ${log} | cut -c1-10)
BeanDate=$(date "+%Y-%m-%d" -d "1 day ago ${LogDate}")
if [[ -z $(grep "${BeanDate}" ${Income}) ]]; then
echo -n "${BeanDate}," >> ${Income}
grep -E "昨日收入" ${log} | grep -oE "\d+" | perl -0777 -pe "s|\n(\d+)|,\1|g" >> ${Income}
fi
if [[ -z $(grep "${BeanDate}" ${Outlay}) ]]; then
echo -n "${BeanDate}," >> ${Outlay}
grep -E "昨日支出" ${log} | grep -oE "\d+" | perl -0777 -pe "s|\n(\d+)|,\1|g" >> ${Outlay}
fi
if [[ -z $(grep "${BeanDate}" ${Total}) ]]; then
echo -n "${BeanDate}," >> ${Total}
grep -E "当前京豆" ${log} | perl -pe "s|\D+(\d+).*|\1|g" | perl -0777 -pe "s|\n(\d+)|,\1|g" >> ${Total}
fi
done