The command below leaves CINxxx.JPS in %TEMP. ( do c in @clip: ( echo %[c]%@execstr[grep %c i.txt | wc -l] ) ) | g:\gnu\sort -n -r --key=2,2 | head /n %cs