#!/bin/bash
#
LINE_MARK="key word to search"
DATE=$(date +%Y-%m-%d)
PRE_DIR=/data/logs/projlog
PRE_FILE=proj.log
FILES=${PRE_FILE}.${DATE}*
for f in `ls ${PRE_DIR}/${PRE_FILE} ${PRE_DIR}/${FILES}`
do
basename $f
sh ./a.sh $f $LINE_MARK
done
#!/bin/bash
#
# split a file into multi sub-files by the unique mark in one line which contain the keyword,
# the lines containing same mark will go into the same file.
#the input file to statistics
fullfilename=${1}
filename=`basename ${1}`
#the keyword to search
keyword=$2
#the path to put the output files
fullpath="$PWD"/output/"$filename"
mkdir -p "$fullpath"
for tid in `grep "$keyword" "$fullfilename" | awk -F'[' '{print $3}'|awk -F']' '{print $1}'|awk -F' ' '{print $1}'`
do
begin=`grep "$tid" "$fullfilename" | head -n1 | awk -F' ' '{print $2}'`
end=`grep "$tid" "$fullfilename" | tail -n1 | awk -F' ' '{print $2}'`
ibegin=`echo ${begin//:/}`
iend=`echo ${end//:/}`
echo $ibegin $iend
bh=${begin:0:2}
bm=${begin:3:2}
bs=${begin:6:2}
eh=${end:0:2}
em=${end:3:2}
es=${end:6:2}
# echo $bh $bm $bs $eh $em $es
etotal=`expr $eh \* 60 \* 60 + $em \* 60 + $es`
btotal=`expr $bh \* 60 \* 60 + $bm \* 60 + $bs`
# echo $btotal $etotal
timecost=`expr $etotal - $btotal`
echo $etotal,$btotal, $timecost
grep "$tid" "$fullfilename" > "$fullpath"/"$timecost"
done