#! /bin/sh case "$1" in '') N=10;; *) N="$1" esac grep -a 'player: *played' "$FILE_LOG_MPD" \ | awk ' BEGIN { s = " *" } $5 == "player:" && $6 == "played" { sub("^" s $1 s $2 s $3 s $4 s $5 s $6 s, "") count[$0]++ } END { for (song in count) printf("%d %s\n", count[song], song) }' \ | sort -n -k 1 -r \ | head -"$N"