0

I have to compare two large files and return the difference of 2 files

$result= Compare-Object -ReferenceObject $(Get-Content D:\Scalability\misc\1.txt) -DifferenceObject $(Get-Content D:\Scalability\misc\1.txt) | Select -Property InputObject
$result.InputObject

above code working for the small file only and file size are 1GB

3
  • 1
    And what is your questiopn? What did you try? There are so many similar questions around, even complete tools that do it for you. Commented Apr 3, 2019 at 6:57
  • For clarity, please add in details like what you are trying to achieve, what problem you are running into, the output you are getting and the expected output. Also include what you have already tried and what you have already read / researched so we don't duplicate efforts here. Commented Apr 3, 2019 at 7:24
  • Hi I want to compare 2 big files and i want difference given 2 file using powershell script or C# Commented Apr 3, 2019 at 7:36

1 Answer 1

1

Use FC command like below:

FC /a C:\demo\input.txt H:\work\output.txt

/a is for ASCII compare

p.s FC stands for file compare

p.s More in the docs: https://ss64.com/nt/fc.html

p.s in powershell we have to write fc.exe or even full path C:\windows\system32\fc.exe because FC is an alias in PowerShell

Sign up to request clarification or add additional context in comments.

6 Comments

FC /a D:\Scalability\misc\1.txt D:\Scalability\misc\2.txt Format-Custom : A positional parameter cannot be found that accepts argument 'D:\Scalability\misc\1.txt'. At line:1 char:1 + FC /a D:\Scalability\misc\1.txt D:\Scalability\misc\2.txt + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Format-Custom], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.FormatCustomCommand
write fc.exe instead
@MaheshGaikwad I updated answer it is because Powershell has an Alias FC for the Format-Custom cmdlet, therefore to run the 'old' FC under PowerShell you need to run fc.exe or full path to fc.exe
Thanks, But i want only different lines from 2 txt file. below is result if i use above code C:\windows\system32\fc.exe /a D:\Scalability\misc\1.txt D:\Scalability\misc\2.txt Comparing files D:\SCALABILITY\MISC\1.txt and D:\SCALABILITY\MISC\2.TXT ***** D:\SCALABILITY\MISC\1.txt 6 8 10 ***** D:\SCALABILITY\MISC\2.TXT 6 ... 10 *****
File 1 have lines 1 2 3 4 5 6 8 10 11 12 and File 2 have 1 2 3 4 5 6 7 8 9 10 11 12 i want result 7 and 9 line which are not exits in file 1
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.