gpt4 book ai didi

bash - 格式化 grep 输出。狂欢

转载 作者:行者123 更新时间:2023-11-29 09:39:26 24 4
gpt4 key购买 nike

尝试格式化 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
...

关于bash - 格式化 grep 输出。狂欢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43126167/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com