我有一个文件,我应该在其中制作“uniq”并显示结果。我的文件:
178.57.66.225 fxsciaqulmlk
178.57.66.225 fxsciaqulmlk
178.57.66.225 fxsciaqulmlk
178.57.66.225 faaaaaa11111
178.57.66.215 terdsfsdfsdf
178.57.66.215 terdsfsdfsdf
178.57.66.215 terdsfsdfsdf
178.57.66.205 erdsfsdfsdf
178.57.66.205 erdsfsdfsdf
178.57.66.205 erdsfsdfsdf
178.57.66.205 erdsfsdfsdf
178.57.66.205 abcbbabab
178.57.66.205 abcbbabab
178.57.66.205 abcbbabab
178.56.66.225 fxsciulmla
178.56.66.225 fxsciulmla
178.56.66.225 fxsciulmla
178.57.67.225 faaaa0a1111
我的脚本:
for i in $(uniq -c /root/log | awk '{print $1}'); do
if [ $i -gt 2 ]; then
s=$(uniq -c /root/log | awk '$1 == '$i | awk '{print $3}')
ss=$(uniq -c /root/log | awk '$1 == '$i | awk '{print $2}')
echo "The bot is user $s with ip $ss"
fi
done
一切正常,但我的输出不正确:
The bot is user fxsciaqulmlk
terdsfsdfsdf
abcbbabab
fxsciulmla with ip 178.57.66.225
178.57.66.215
178.57.66.205
178.56.66.225
The bot is user fxsciaqulmlk
terdsfsdfsdf
abcbbabab
fxsciulmla with ip 178.57.66.225
178.57.66.215
178.57.66.205
178.56.66.225
The bot is user erdsfsdfsdf with ip 178.57.66.205
The bot is user fxsciaqulmlk
terdsfsdfsdf
abcbbabab
fxsciulmla with ip 178.57.66.225
178.57.66.215
178.57.66.205
178.56.66.225
The bot is user fxsciaqulmlk
terdsfsdfsdf
abcbbabab
fxsciulmla with ip 178.57.66.225
178.57.66.215
178.57.66.205
178.56.66.225
我在两天内完成了,我不明白我在哪里犯了错误?请帮忙。
当,我在条件下增加 uniq 的数量:
if [ $i -gt 2 ]; then
我有一个正常的日志:
The bot is user erdsfsdfsdf with ip 178.57.66.205
我哪里有错误?
如果要计算唯一行并仅显示重复超过 3 次的行,可以使用以下
-c
选项uniq
:过滤器
awk
输出以显示重复次数超过 3 的行,然后根据需要格式化输出。请注意,这要求文件已经排序,因为从您的帖子中可以清楚地看出。