3

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

user3151135
  • 35
  • 1
  • 5

4 Answers4

5

This should work:

findstr /v /g:file1.txt file2.txt >result.txt

This works for 800 char I think - it won't be quick for 20000 lines.

@echo off
for /f "delims=" %%a in (file2.txt) do (
   find "%%a" <"file1.txt" || >>result.txt echo %%a
)
foxidrive
  • 40,353
  • 10
  • 53
  • 68
  • It's a bit slow, but finally works! Thank you. Cheers – user3151135 Jan 01 '14 at 12:49
  • There's still something wrong with this. My file1.txt has something like this: "land_units_onscreen_name_Aet_Cav" "Aithiopes Hippeis" "True" "land_units_onscreen_name_Aet_Sword" "Aithiopes Makhairaphoroi" "True" and when I've tried to comprate it to file2.txt my cmd displays this: File not found - land_units_onscreen_name_Aet_Cav TRUE and my output file is just copy of file2.txt – user3151135 Jan 01 '14 at 13:16
  • Try the findstr solution above the find solution. Your string has poison characters for plain batch. The quotes affect it. – foxidrive Jan 01 '14 at 13:21
  • it says "Findstr search string too long" – user3151135 Jan 01 '14 at 13:22
  • maybe is there a way to replace those characters on different ones and place them back after whole process? There're also tabs between " " – user3151135 Jan 01 '14 at 13:23
  • Try the powershell solution below from "Joachim Isaksson" – foxidrive Jan 01 '14 at 13:25
  • It is possible to change the quotes and change them back later, but that would require another batch file using Jscript or VBS or Powershell, and the Powershell solution alone should be more robust and works in a batch file. – foxidrive Jan 01 '14 at 13:30
  • Thank you for your help, I am grateful :) Already found help. – user3151135 Jan 01 '14 at 13:32
2

PowerShell has a diff utility if that's an option;

@echo off
powershell "diff (Get-Content File1.txt) (Get-Content File2.txt) | foreach {$_.InputObject}" >result.txt
foxidrive
  • 40,353
  • 10
  • 53
  • 68
Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
1

Use the comm utility (http://linux.101hacks.com/unix/comm-command-examples/):

comm -3 file1.txt file2.txt > file3.txt
anyaelise
  • 92
  • 1
  • 7
1

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
Jotne
  • 40,548
  • 12
  • 51
  • 55