簡體   English   中英

格式化grep輸出。 巴什

[英]Formatting grep output. Bash

試圖格式化grep的輸出以使其看起來更好,代碼是

grep "$1" "$2" | grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" | sort | uniq -c
$ bash myScript.sh "Failed password for root" /home/user/auth.log 
      5 108.166.98.9
   1426 108.53.208.61
      1 113.108.211.131
      1 117.79.91.195
    370 122.224.49.124
   3480 144.0.0.32
     11 162.144.94.250
      6 162.253.66.74
      3 186.67.83.58
      1 222.190.114.98
    205 59.90.242.69
    705 60.172.228.226
      3 64.251.21.104

並希望它看起來更像

ip: xxx.xxx.xxx.xxx attempts: X

uniq之后,將以下命令添加到腳本中管道的末尾:

... | awk '{print "ip: " $2 " attempts: " $1}'

輸出將是

ip: 108.166.98.9 attempts: 5
ip: 108.53.208.61 attempts: 1426
...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM