grep / awk数组来自文本maches的行

时间:2017-07-17 15:08:36

标签: linux awk

我试图创建一个搜索.log文件中某些行的shell脚本。 我需要首先搜索数字并将它们放入一个文件中,然后在该文件中搜索每个ID并将它们存储在数组中,以便再次在文件中搜索响应。

代码:

#!/bin/bash
logFile='/path/to/file.log'
if [[ $1 = "" ]]; then
        echo "Use ./analize.sh <number>";
        exit 0
fi
result=rs-$1.log;
touch result;
grep -B 7 -A 1 $1 $logFile >> result;
IDarr[i]=($(cat result | grep 'ID:'))
while [ -n "$IDarr[i]" ]
        do grep -B 2 -A 6 ${IDarr[n]} $result >> idmatched.log
done
exit 0

由于

logfile示例:

017-06-13 12:00:32 - Outbount Request
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
ID: 132
Request: [FW1;14dwa90266681;12eqw28631898;99514;321;634579;224943746;2]
Encription: YES
Export-Value: 2048
Type: String
Content: {Status=[Failed], Target={"number":"9892213994","asID":"a321kpok41hadw-0-391-12391421.00","version":"09e2da8d-7379-39d9-9c52-be4aba0d49d1", t-qgs-ms=[4], java 1.7, h-ucc-dn=[***************************]}, accept-encoding=[identity], Content-Length=[300],}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

2017-06-13 12:10:51 - Inbound Response
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
ID: 132
Response-Code: 200
Encription: YES
Export-Value: 2048
Headers: {Content-Length=[39], charset=UTF-8], Date=[13 Jun 2017 12:10:51 GMT]}
Load: {"result":"E9W2KE3MNA","Message":"Successful"}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

0 个答案:

没有答案