#!/bin/bash#by lc at 20160428 for hadoop (grep_recharge) DATE= ' Date +%F_%H\:%M\:%S ' ytdate= ' date -d " -1 day" +%y%m%d ' restdir=/home/hadoop/prodata/restdatedir=/home/hadoop/ prodata/rest/$YTDATERESTFILE =${datedir}/recharge-$YTDATE. log#restfile=recharge-20160427.log#newfile= parse-recharge.lognewfile=${datedir}/parse-recharge-$YTDATE. Loglogfile=/server/scripts/grep_ Recharge.logfunction checkfile () {> $NEWFILEWCRESTFILE = ' wc -l $RESTFILE ' echo ' ##### ################### ' >> $LOGFILEecho "${date} go ..." >> $LOGFILEecho "$WCRESTFILE" >> $LOGFILEif [ ! -e $RESTFILE ] then echo "$RESTFILE cant find" >> $LOGFIL exit 1fi}function grepfile () {egrep -v "Rechmoney|money_order" ${RESTFILE}|grep -v ' cardnum ' |awk -f '[{] ' ' {print $1} ' |sed -nr ' s# (. *) #\1\{\} #gp " >${newfile}###### #CardNumegrep - v "Rechmoney|money_order" ${RESTFILE}|grep ' Cardnum ' |grep "[0-9]\{8\}\" \}$ "|sed -nr ' s# (. *) \{.*\}#\1\{\} #gp ' >>${NEWFILE}egrep -v "Rechmoney|money_order" ${ restfile}|grep ' Cardnum ' |grep -v "[0-9]\{8\}\" \}$ "|tr ' {} ' ' 1 ' |sed -nr ' s# ( . *) #\1\|\{\} #gp ' >>${newfile}##### #Money_Ordergrep "Money_order" ${RESTFILE}|sed ' s# \\# #g ' |tr ' {' ' # ' |sed -nr ' s# (. *) \#.*\#.*money_order (. *) #\1\{\ "RECHMONEY\2#GP ' |sed ' s #\## #g ' |sed ' s#iphone[0-9],[0-9] #iPhone #g ' |sed ' s#ipod[0-9],[0-9] #iPod #g ' |sed ' s#ipad[0-9],[0-9 ] #iPad #g ' |awk -f[,] ' {print $1 "\,\" recharge\ "\:\" param\ "\}"} ' |sed ' s#\ ' data\ ': # #g ' >>${newfile}###### #rechMoneygrep "Rechmoney" ${RESTFILE}|sed ' s#\\# #g ' |tr ' {' ' # ' |sed -nr " s# (. *) \#.*rechmoney (. *) #\1\ "RECHMONEY\2#GP" |sed ' s#\## #g ' |sed ' s#iphone[0-9],[0-9] #iPhone #g ' |sed ' s#ipod[0-9],[0-9] #iPod #g ' |sed ' s#ipad[0-9],[0-9] #iPad #g ' |awk -f ' [,] ' ' {print $1} ' | sed ' s#\}# #g ' |awk -f ' ["] ' ' {print $1" \{\ "" $ "\" "$ $" \ "$4" \ "\,\" recharge\ "\:\" param\ "\}"} ' >>${NEWFILE}echo "' Wc -l ${newfile} ' " >> $LOGFILEif [ $? -ne 0 ] then echo "' date +%f_%h\:%m\ :%s ' not ok ' >> $LOGFILE else echo "' date +%f_%h\:%m\:%s ' ok" >> $LOGFILEfi}main () { checkfile grepfile}main
This article is from the "10886311" blog, please be sure to keep this source http://10896311.blog.51cto.com/10886311/1836643
Shell's log processing