我想从输入中读取文本文件并逐块读取。我不想逐行读取输入文件,我不想使用AWK,因为块应该在while或for中。如何用while或for循环逐块读取文本文件?这是我的剧本:
#!/bin/bash
awk -v RS='Uri' '{ print $0 }' parse_xml
while read -r i # problem is here, read command can't read block input
do
Uri=$(awk '{print $3}' $i)
Status=$(echo $i | awk '/Status/{print $3 }' )
Country=$(echo $i | awk '/Country/{print $3 }')
IP=$(echo $i | awk '/IP/ {print $3}')
HTTPServer=$(echo $i | awk '/HTTPServer/ {print $3}')
Title=$(echo $i | awk '/Title/ {print $3}')
PoweredBy=$(echo $i | awk '/X-Powered-By/ {print $3}')
ASP_NET=$(awk '/ASP_NET/ {print $3}' $i)
JQuery=$(awk '/JQuery/ {print $3}' $i)
Microsoft_IIS=$(awk '/Microsoft-IIS/ {print $3}' $i)
Apache=$(awk '/Apache/ {print $3}' $i)
echo "$Uri -- $Status -- $Country -- $IP -- $STTPServer -- $Title -- $PoweredBy -- $ASP_NET -- $JQuery -- $Microsoft_IIS -- $Apache "
done < pars_xml
这是我的输入文件:
: http://xxxxxxxxxxxxxxx
Status : 200
nginx : 1.2.1
Country : xxxxxxxxxxxxxxxx
Title : Welcome to nginx!
IP : xxxxxxxxxxxxxxx
HTTPServer : nginx/1.2.1
: http://xxxxxxxxxxxxxxxx
Status : 200
X-Powered-By : ASP.NET
HttpOnly : ASP.NET_SessionId
HTML5 :
ASP_NET : 4.0.30319
Country : xxxxxxxxxxxxxxxxxxxxx
Title : .:%D9%BE%D8%A7%DB%8C%DA%AF%D8%A7%D9%87 %D8%A7%D8%B7%D9%84%D8%A7%D8%B9 %D8%B1%D8%B3%D8%A7%D9%86%DB%8C %D8%B2%D8%A7%D8%A6%D8%B1%DB%8C%D9%86:.
Script : text/javascript
Cookies : ASP.NET_PrivateSessionID ASP.NET_SessionId
IP : xxxxxxxxxxxxxx
JQuery : 1.4.2
HTTPServer : Microsoft-IIS/7.5
Microsoft-IIS : 7.5
: http://xxxxxxxxxxxxxx
Status : 200
Meta-Refresh-Redirect : /Intranet
X-Powered-By : ASP.NET
ASP_NET :
Country : xxxxxxxxxxxxxxxxxxxx
IP : xxxxxxxxxxxxxxxxxxxx
HTTPServer : Microsoft-IIS/7.0
Microsoft-IIS : 7.0
: http://xxxxxxxxxxxxxxxxxxxxx
Status : 301
X-Powered-By : ASP.NET
ASP_NET :
Country : xxxxxxxxxxxxxxxxxx
Title : Document Moved
IP : xxxxxxxxxxxxxxxxxxxxx
HTTPServer : Microsoft-IIS/7.0
Microsoft-IIS : 7.0
RedirectLocation : http://xxxxxxxxxxxxxxxxxx