我有一个日志文件包含所有信息。如何使用bash中的parametres从文件中提取行
2017-09-21 02:01:11,130 [http-nio-8080-exec-5] INFO - Inbound Message
...
...
2017-09-21 09:01:11,130 [http-nio-8080-exec-5] INFO - Inbound Message
----------------------------
ID: 6044
Address: http://localhost/serveur/Service?wsdl
Encoding: UTF-8
Http-Method: POST
...
2017-09-21 12:01:11,130 [http-nio-8080-exec-5] INFO - Inbound Message
...
我想只提取2个日期之间的信息。对于为例,如果我想2017年9月21日09 ..和2017年9月21日12之间的信息我想有这样的事情:
./script.sh 2017-09-21 09 2017-09-21 12
# $1 = 2017-09-21
# $2 = 09
# $3 = 2017-09-21
# $4 = 12
# $1 & 2 are date and hour to begin extract
# $3 & 4 are date and hour to finish extract
我的剧本是这样的。我没有shell编程知识,但我试图做到这一点。不幸的是它不起作用
#!/bin/bash
beginLine = "$1 $2"
finishLine = "$3 $4"
while read fileLog.log
do
if($fileLog.log grep beginLine)
echo $fileLog.log >> extractedlog.log
fi
if($fileLog.log grep finishLine)
< extractedLog.log;
fi
done
exit 0;
有谁能告诉我问题在哪里?
这不是'bash'语法 – hek2mgl