我有這個腳本,我建立了它,它工作正常,但我想結合2個awks在一個所以我,我有1行的所有信息,這可能嗎?從域結合在一個bash中的2個awk循環
for i in `cat domains` ; do
IFS='=' read -a array <<< "$i"
CC=`echo "${array[0]}"`
awk -v c=$CC '{a[substr($4,2,17)]++}END{for(i in a){print i, a[i], c}}' "${array[1]}".access_log | sort
awk -v c=$CC '{if ($0 ~ /html/) b[substr($4,2,17)]++}END{for(j in b){print j, b[j], c}}' "${array[1]}".access_log | sort
exit
done
片段:
af=www.google.com.af
al=www.google.al
ao=www.google.co.ao
ar=www.google.com.ar
au=www.google.com.au
例如: 給出AF = www.google.com.af 針對www.google.com.af.access_log運行
- - - [21/Jul/2014:14:35:18 +0200] "GET /apple-touch-icon.png HTTP/1.1" 404 246 "-" "MobileSafari/9537.53 CFNetwork/672.1.15 Darwin/14.0.0" 556
- - - [21/Jul/2014:14:35:18 +0200] "GET /apple-touch-icon.png HTTP/1.1" 404 246 "-" "MobileSafari/9537.53 CFNetwork/672.1.15 Darwin/14.0.0" 556
- - - [21/Jul/2014:14:36:18 +0200] "GET /apple-touch-icon.png HTTP/1.1" 404 246 "-" "MobileSafari/9537.53 CFNetwork/672.1.15 Darwin/14.0.0" 556
- - - [21/Jul/2014:14:36:18 +0200] "GET /main.html HTTP/1.1" 404 246 "-" "MobileSafari/9537.53 CFNetwork/672.1.15 Darwin/14.0.0" 556
- - - [21/Jul/2014:14:36:18 +0200] "GET /main.html HTTP/1.1" 404 246 "-" "MobileSafari/9537.53 CFNetwork/672.1.15 Darwin/14.0.0" 556
- - - [21/Jul/2014:14:37:18 +0200] "GET /main.html HTTP/1.1" 404 246 "-" "MobileSafari/9537.53 CFNetwork/672.1.15 Darwin/14.0.0" 556
- - - [21/Jul/2014:14:37:18 +0200] "GET /main.html HTTP/1.1" 404 246 "-" "MobileSafari/9537.53 CFNetwork/672.1.15 Darwin/14.0.0" 556
- - - [21/Jul/2014:14:37:18 +0200] "GET /main.html HTTP/1.1" 404 246 "-" "MobileSafari/9537.53 CFNetwork/672.1.15 Darwin/14.0.0" 556
應該返回
21/Jul/2014:14:35 total: 2 html: 0
21/Jul/2014:14:36 total: 3 html: 2
21/Jul/2014:14:37 total: 3 html: 3
請顯示'domains'的樣本。 – konsolebox
編輯你的答案向我們展示一個'domains'的例子會很有用。 –
如果我們有'域'的一些數據和你喜歡的結果,我們可以在'awk'中完成所有的',''''IFS'等等。 – Jotne