by indescions_2017 · 9y ago · 0 comments
Me too. For example, number of unique IP requests in a log file in milliseconds ;)
$ awk '{ print $1 } ' caddy_log | sort | uniq | wc -l
But rarely compose my own from scratch. It's mostly copy paste. And store in admin bin for future use.
$ cat duplicates.txt
abc 7 4
food toy ****
abc 7 4
test toy 123
good toy ****
$ awk '!seen[$2]++' duplicates.txt
abc 7 4
food toy ****
$ awk '!seen[$2]++{cnt++} END{print +cnt}' duplicates.txt
2 awk '{ip[$1]=1}; END{ print length(ip) }'
Use the hash tables directly, assuming you've got the memory. That should be slightly faster as it avoids the sort.also, {ip[$1]} is enough...