linux - Shell script to read a list of words and compute their counts in a corpus. -
i need write command line script in linux following:
read list of words text file (one word per line). w_i
for each w_i computes word count in different text file.
sum on these counts
some here appreciated!
this grep line may work you, give try:
grep -ofwf wordlist textfile|wc -l
i did small test, seems worked expected.
(ps, insert words in file2 using vim, know how many inserted)
kent$ head file1 file2 ==> file1 <== foo bar baz hello world ==> file2 <== foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world blah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo bablah bbbb fo ba kent$ grep -ofwf file1 file2|wc -l 66
Comments
Post a Comment