sed 的主要作用是替换,awk 作用是格式化输出
样本文件
I, [2017-01-03T00:00:07.420412 #89085] INFO -- : unpack string is BB,03,12,34,56,78,17,EE,
I, [2017-01-03T00:00:07.420461 #89085] INFO -- : {:content=>["BB,03,12,34,56,78,17,EE,"], :type=>"from_terminal"}
I, [2017-01-03T00:00:07.420519 #89085] INFO -- : command body: 03,12,34,56,78,17,
命令
grep "is BB" log/gps.log | sed "s/.*\[\(.*\)T\(.*\) #.*string is\(.*\)/\1 \2 \3/g" | awk '"2017-01-03" < $1 && "16:48:00" < $2 {print}'
输出
2017-01-04 16:58:01.310148 BB,01,12,34,56,78,15,EE,