#!/bin/bash for logfile in /var/log/*log; do echo "Processing: $logfile" # the following line splits the logfile entry line with an empty space as delimiter and then keeps only everything from field five onwards cut -d" " -f5- $logfile | sort | uniq -c | sort -nr | head -5 done