cat log.log|grep -E -o 'remote_ip=[0-9.:]*'|awk '{a[$1]+=1;}END {for(i in a){print a[i] i}}'|sort
remote_ip=
匹配要篩選的ip標識
egrep -o "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" billing.log -c
統(tǒng)計IP出現(xiàn)的次數(shù)
egrep等同于grep -E 表示過濾多個參數(shù) grep -E "hello|sshd"
-o 僅打印你需要的東西
\b 作為邊界符悯衬,邊界只包含特定字符的行
-c 統(tǒng)計出現(xiàn)的次數(shù)
正則表達式
[0-9] 數(shù)字
{1,3} 1位到3位
([0-9]{1,3}\.){3} -- ip 數(shù)字1-3位加小數(shù)點檀夹,重復三遍
[0-9]{1,3} -- ip 數(shù)字1-3位