Skip to content
Advertisement

Comparing tow large files line by line

I was wondering if there is any efficient way to compare 2 large files line by line.

File 1

JavaScript

File 2

JavaScript

I am just taking the first character of each file and comparing against them. Currently i am using a very naive method of iterating through them in a double for loop.

Like

JavaScript

Reading both files into memory is not an option. I am using python on linux but i am open to both bash solutions and python script solutions

Advertisement

Answer

What about something like this:

JavaScript

diff is the tool you use to compare files’ lines. You can use process substitution (anonymous pipe) to compare a version of each file only containing the first character (using cut).

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement