- List of commands you use most often
history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
- Remove duplicate entries in a file without sorting.
Using awk, find duplicates in a file without sorting, which reorders the contents. awk will not reorder them, and still find and remove duplicates which you can then redirect into another file.
awk '!x[$0]++' <file>
- Analyse an Apache access log for the most common IP addresses
This uses awk to grab the IP address from each request and then sorts and summarises the top 10.
tail -10000 access_log | awk '{print $1}' | sort | uniq -c | sort -n | tail
- Using awk to sum/count a column of numbers. Takes a input file (count.txt) that looks like: 1 2 3 4 5 It will add/sum the first column of numbers.
cat count.txt | awk '{ sum+=$1} END {print sum}'
- list all file extensions in a directory
find . -type f | awk -F'.' '{print $NF}' | sort| uniq -c | sort -g