1

I have two file's with 3 GB each to do a comparison and store the difference data into third file.

Following is the sample data.

File 1: June_01_2018.csv

enter image description here

File 2: June_02_2018.csv

enter image description here

Note: I want to store the difference into the third file with the column headers.

Expected Result: The third file should contain the records from ID 11 to 15 with the column headers.

My try: fc command in command prompt,

>fc June_01_2018.csv June_02_2018.csv > June_Diff.csv

But getting unexpected result:

enter image description here

1
  • 1
    Related: How to compare two csv files in windows. fc is an interactive command line tool, i.e. it will always produce human readable output. Additionally, it compares text files line by line and doesn't know about the meaning of the lines. In your case, the first line containing the column headers is identical in both files, so it isn't printed. If you read the docs, you will see that your output is the expected output. I doubt fc is the right tool for this task.
    – danzel
    Jun 5, 2018 at 8:55

1 Answer 1

1

Hopes have nothing to do with (realistic) expectations.

The header is exactly the same, so could never be a difference.
Also the excel representation is not the csv file, you should post the original files as text.

The following batch file reads in the header and echoes to the diff.
Instead of fc it uses findstr with options

/B compare from line begin
/E compare upto line end
/V output lines **not** present in compared file
/G: get strings from a file

@Echo off
Set "File1=June_01_2018.csv"
Set "File2=June_02_2018.csv"
Set "File3=June_Diff.csv"

Set /P "Header="<"%File1%"
( Echo=%Header%
  Findstr.exe /BEV /G:"%File2%" "%File1%"
)>"%File3%"

Variant with fc

@Echo off
Set "File1=June_01_2018.csv"
Set "File2=June_02_2018.csv"
Set "File3=June_Diff.csv"

Set /P "Header="<"%File1%"
( Echo=%Header%
  fc "%File1%" "%File2%"|more +3 
)>"%File3%"

That leaves only the trailing line.

9
  • Getting an error FINDSTR: Search string too long.
    – MAK
    Jun 6, 2018 at 7:45
  • What file sizes are you dealing with?
    – LotPings
    Jun 6, 2018 at 8:22
  • File is of 3 GB each.
    – MAK
    Jun 6, 2018 at 8:29
  • Well that definetly exceeds findstr limits You can use the Header approach, append the fc variant and tweak the output by removing the unwanted lines starting with comparing and *****
    – LotPings
    Jun 6, 2018 at 8:40
  • I tried with fc command with your code. But getting error RESYNC FAILED. To overcome with this I just added /Lb 200000 to fc because of the difference between two files comes with around 1 millions more or less records. The script is still running from last 15 min..
    – MAK
    Jun 6, 2018 at 8:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .