我是shell脚本的新手,并试图从文件中读取最后2小时的日志,但得到一些语法。有人请帮帮我..
我的日志文件内容是:
AppDebug,2011-12-18 12:08:45:990,ret521v,TEST,TEST Hub,,,,,,,2,49601060
AppDebug,2011-12-18 12:09:34:891,ret521v,TEST,TEST Hub,,,,,,,4,49588825
AppDebug,2011-12-18 12:10:08:485,ret521v,TEST,TEST Hub,,,,,,,4,49588826
AppDebug,2011-12-18 12:11:21:603,ret521v,TEST,TEST Hub,,,,,,,4,49588827
AppDebug,2011-12-18 12:12:05:430,ret521v,TEST,TEST Hub,,,,,,,4,49588828
AppDebug,2011-12-18 12:12:08:376,ret521v,TEST,TEST Hub,,,,,,,38,ResponseTrackId49588828
#!/bin/sh
awk -vDate=`date -d'now-2 hours' +%Y-%m-%d" "%H:%M:%S` '{ if ($2 > Date) print ;}' test.log
awk: 11:50:00
awk: ^ syntax error
答案 0 :(得分:2)
awk -F"," -vDate="`date -d'now-2 hours' +%Y-%m-%d" "%H:%M:%S`" '{ if ($2 > Date) print ;}'
两件事:将昏迷指定为字段分隔符,并在“Date”变量的值周围加上引号。