output 1: Try this code. if needed make adjustments
bash-4.1$ cat test.sh #!/bin/bash OUTPUT_FILE=/tmp/output.txt awk '{ for(i=1;i<=NF;i++) { Arr[$i]++ } } END{ for (i in Arr){ if(Arr[i]>1) { print i":"Arr[i] } } }' file* > ${OUTPUT_FILE} cat ${OUTPUT_FILE} echo "" IFS=":" while read WORD TOTAL_COUNT do echo "${WORD}:" for FILE_NAME in file* do COUNT=$(tr ' ' '\n' < ${FILE_NAME} | grep -c "${WORD}") if [ "${COUNT}" -gt "0" ] then echo "${FILE_NAME}:${COUNT}" fi done done < ${OUTPUT_FILE} bash-4.1$ bash test.sh beautiful:3 so:3 beautiful: file1:1 file2:1 file3:1 so: file1:1 file2:1 file3:1