2

I have two files: one which is the dictionary, and the other one corresponds to the list of words that appear in a transcription. I need to output the words out of vocabulary words. This is:

dict.txt
you 
she
apple
banana
strawberry
eat

transcript.txt
you
strawberry
and 
banana
<silence>
for 
breakfast

So, my desired output would look like this:

and
for
breakfast
<silence>

Is there any command output such words that are not found in the dictionary? thanks in advance!

don_crissti
  • 82,805

1 Answers1

3
grep -vf dict.txt transcript.txt
    and
    <silence>
    for
    breakfast

fix

The above solution treats the file content as patterns. That does work in this example but not in general. In order to match the full lines literally you need:

grep -vFxf dict.txt transcript.txt
Hauke Laging
  • 90,279
  • When I run that command I got "killed" :/ – little_mice May 12 '18 at 12:22
  • @little_mice: Where is killed coming from? Is it an error or a word in one of your files? – jesse_b May 12 '18 at 12:35
  • When I run that command in the terminal it outputs "killed" in the same terminal. And the file where the output should be redirect is empty – little_mice May 12 '18 at 13:10
  • 1
    This command must be run in the directory containing dict.txt and transcript.txt (or specify the full path to those files. Also this command as is will not produce an output file (because you have not asked for one), it will send the output to stdout. – jesse_b May 12 '18 at 13:19
  • it finally worked! the problem was that it wasn't run in the directory was @Jesse_b said. Thanks! – little_mice May 12 '18 at 15:59
  • i'm looking for similar script, if i put word patterns in dict.txt instead of actual word, will it work? – jerry Mar 08 '21 at 04:42
  • @jerry It is even worse. It does not only work, that would even be considered an error in my original answer. In order to match literal words you need grep -Fxf. – Hauke Laging Mar 08 '21 at 12:19
  • @HaukeLaging, thanks, i tested from my end, grep -vf does read dict.txt as pattern, and it works for me – jerry Mar 08 '21 at 13:09