我想知道有多少用戶在最近30分鐘內使用我的代理訪問了google.com。從awk輸出中計算唯一值
awk -v bt=$(date "+%s" -d "30 minutes ago") '($1 > bt) && $4~/google.com/ {printf("%s|%s|%s|%s\n", strftime("%F %T",$1), $2 , $3, $4)} ' access.log
日誌看起來是這樣
2017-02-19 12:09:44|[email protected]|200|https://google.com/
2017-02-19 12:10:23|[email protected]|200|https://google.com/
現在,我可以很容易計算的記錄數
awk -v bt=$(date "+%s" -d "30 minutes ago") '($1 > bt) && $4~/google.com/ {printf("%s|%s|%s|%s\n", strftime("%F %T",$1), $2 , $3, $4)} ' access.log | wc -l
輸出爲2
如何修改命令僅顯示具有唯一電子郵件的記錄。在上述情況下,輸出應爲1.