Search code examples
stringbatch-filegrepcomparefindstr

Batch, comparing two files and write differences to another file


I've searched for solution but I still have problems with it. I have two files:

File1.txt
 1111
 2222
 3333

File2.txt
 1111
 2222
 3333
 4444

and I want an output file with only differences:

File3.txt
 4444

I've tried using Findstr but it doesn't work due to too large strings. I've also tried with gerp but I can;t make it to work.

Here's my batch code (it doesn't work because of too long strings):

findstr /vxg:vanilla_localisation.tsv mod_localisation.tsv > raf_changes.tsv 
for /f %%a in ('^<raf_changes.tsv find /v /c ""') do echo %%a differences found 

I've tried also with this code:

grep -f vanilla_localisation.tsv mod_localisation.tsv > raf_changes.tsv

but it creates only empty file. I'm windows user. Hope you will help me find solution.

Cheers


Solution

  • You can use diff in linux

    diff file1.txt file2.txt
    3a4
    >  4444
    

    Using grep

    grep -vf file1.txt file2.txt
     4444
    

    Using awk

    awk 'NR==FNR {a[$0]=1;next} !a[$0]' file1.txt file2.txt
     4444