Artificial intelligent assistant

Count lines containing word I have a file with multiple lines. I want to know, for each word that appears in the total file, how many lines contain that word, for example: 0 hello world the man is world 1 this is the world 2 a different man is the possible one The result I'm expecting is: 0:1 1:1 2:1 a:1 different:1 hello:1 is:3 man:2 one:1 possible:1 the:3 this:1 world:2 Note that the count for "world" is 2, not 3, since the word appears on 2 lines. Because of this, translating blanks to newline chars wouldn't be the exact solution.

Another Perl variant, using List::Util


$ perl -MList::Util=uniq -alne '
map { $h{$_}++ } uniq @F }{ for $k (sort keys %h) {print "$k: $h{$k}"}
' file
0: 1
1: 1
2: 1
a: 1
different: 1
hello: 1
is: 3
man: 2
one: 1
possible: 1
the: 3
this: 1
world: 2

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy accb2491081d3a1b34130346546ade41