截取日志

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/bin/sh

logFileName="pcrf_stack.log"
startTime="2014-10-11T22:30:00"
endTime="2014-10-11T23:30:00"
outPutFileName="./stack_log_2230_2330.log"

startLineNum=`grep -n "$startTime" $logFileName | head -n1 | awk -F: '{print $1}'`
endLineNum=`grep -n "$endTime" $logFileName | head -n1 | awk -F: '{print $1}'`

echo $startLineNum
echo $endLineNum

sed -n "${startLineNum}, ${endLineNum}w $outPutFileName" $logFileName