test.log
1;0;11 2;1;22 3;3;33 5
#!/bin/sh echo $# if [[ $# > 0 ]];then green_day=$1 else green_day=`date +%Y%m%d` fi
阿萨德 echo $green_day log_day=`date +%Y-%m-%d -d "1 day ago $green_day"` echo $log_day month=`date +%Y-%m -d "$log_day"` day=`date +%d -d "$log_day"` echo "greenday:$green_day logday:$log_day" LOG_DIR=/root/to/path/$month/$day echo $LOG_DIR sed -e 's/;[^01]/9/g' -e 's/5/8/g' test.log awk -F';' 'BEGIN{OFS="\t"}{if(($1 == 1 && $2 == 0) || $1 == 2){print '$green_day',FILENAME,$1,$2,$3}}' test.log
awk
cat test.log |awk -F';' 'BEGIN{OFS="\t"} $1=='1' {a1++;a2++} {print a1,a2,$1,$2,$3} END{print a1}'
a1/a2初始值为0,
MySQL
mysql -h127.0.0.1 -uuser -ppwd -D database -e "show tables; delete from table_name where date='$green_day'; LOAD DATA LOCAL INFILE 'xx.log' INTO TABLE table_name(field1,field2);"