I have a file, where i should make "uniq" and show result. My file:
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
My script:
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
All ok, but my output is not correct:
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
I am making it during 2 days, and i can't understand where i make mistake ? Please help.
When, i increase number of uniq in condition:
if [ $i -gt 2 ]; then
I have a normal log:
The bot is user erdsfsdfsdf with ip 178.57.66.205
Where i have mistake ?
If you want to count the unique lines and show only the ones which repeated more than 3 times, you can use
-c
option ofuniq
like:The
awk
fitlers the output to show lines with more than 3 repetitions, and then formats the output as desired.Please, note that this requires the file to be already sorted as it is clear from your post.