Need Help in comparing 2 text files in shell script

Hi All,

I have 2 files like below

vi f1

frog
elephant
rabit
zebra
dog

vi f2

rabit
dog

==============

Now i want to comapre two files and the result will be

frog
elephant
zebra

that means...the elements are not in f2 while compare with f1

Kindly do me helpfull

Thanks

You may use comm command. Look at

man comm
nawk 'FNR==NR{a[$1]++;next}!a[$1]' f2 f1
use awk for linux

Try:

grep -vf f2 f1
1 Like

Thank you very much for replying me.

I have used

comm-3 f1 f2

...but i m not getting the required out put

comm only works on lexically sorted files.

my grep does not support "f" option unfortunately so i went for awk.

bash-3.00$ grep -vf f2 f1
grep: illegal option -- f
Usage: grep -hblcnsviw pattern file . . .

i got it by using " grep -vf f2 f1".... Thanks a lot

Try /usr/xpg4/bin/grep instead