A pure bash answer
echo "0 hello world the man is world 1 this is the world 2 a different man is the possible one" | while IFS=$'\n' read -r line; do echo $line | tr ' ' '\n' | sort -u; done | sort | uniq -c 1 0 1 1 1 2 1 a 1 different 1 hello 3 is 2 man 1 one 1 possible 3 the 1 this 2 world I looped unique words on each line and passed it to uniq -c
edit: I did not see glenn's answer. I found it strange to not see a bash answer