-1

I have two files: in linux redhat version 6

list1.txt - this files contain 34732 words

list2.txt - this files contain 272 words

I want to remove all words from list1.txt that spears from list2.txt

what the best approach to do that ( both files include only one field )

more list1.txt

dweferf
fr
grgr
gefyh
fergtrg
ggtgg
fergth
gtg
.
.
.

more list2.txt

dweferf
fr
frgrgggb
rggtgtrgrt
fergtrg
rfergrtg
fwed4

.
.
.
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
yael
  • 1,521

1 Answers1

-1

You can do something like this too,

#!/bin/bash
FILE1=$1 # path to your list2.txt
FILE2=$2 # path to your list1.txt
touch ./tmpfile
FILE3=./tmpfile
while read p; do
  if [ `grep "\<$p\>" $FILE2 | wc -l` -ne 0 ] 
  then
    echo "$p word found discarding"
  else
    echo -e "$p" >> $FILE3
  fi
done <$FILE1
mv $FILE3 $FILE2