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

4
  • If you have access to for example cygwin, you probably want diff, not grep. – Joachim Isaksson Jan 1 '14 at 12:24
  • I do not have access to cygwin. – user3151135 Jan 1 '14 at 12:30
  • Are the lines longer than 8191 characters? How many lines are in the files, roughly? – foxidrive Jan 1 '14 at 12:33
  • no, they are 10-800 max There're about 20000lines – user3151135 Jan 1 '14 at 12:35
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
1
  • Thank you, second solution helped me :) – user3151135 Jan 1 '14 at 13:31
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
)
8
  • It's a bit slow, but finally works! Thank you. Cheers – user3151135 Jan 1 '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 1 '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 1 '14 at 13:21
  • it says "Findstr search string too long" – user3151135 Jan 1 '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 1 '14 at 13:23
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
1

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

comm -3 file1.txt file2.txt > file3.txt
1
  • I'm windows user, so I can't use it – user3151135 Jan 1 '14 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.