Compare line by line of two text file and find the difference

Hello All,

I have two text file and want to compare line by line of both files and find out the difference Attached both the text files.
result_file_1.zip (6.5 KB)
result_file.zip (13.0 KB)

You can use a regex to split text files by new file System.Text.RegularExpressions.Regex.Split( firstfile,"\r?\n" )
saved in array of string.
do the same thing for the second one and you can compare with for each, by using the index of for each to navigate in the second file.
Add a try catch with exception index out of range to break the loop when the range is different.


also you have here the zip file sample
campareLineByLine.zip (16.1 KB)

@dutta.marina,

Try this approach:

Solution:

Output:
image

Sample Code:
CompareTextFile.xaml (8.3 KB)

Thanks,
Ashok :slight_smile:

1 Like

@ashokkarale

If instead of text file, I have the file format in PDF, how can I compare two PDF line by line.

@Luciano_Gjinaj

If instead of text file, I have the file format in PDF, how can I compare two PDF line by line.Also, instead of True False, I want to write the difference in two lines. What are the differences.

if you want to add the differences do this steps.

  1. crate and array outside the loop
  2. whenever is false just split the part when is different
  3. add in the array, when is false

if you want to compare the pdfs line by line you need to convert it in the text file, in my knowledge I don’t know any way to compare pdfs line by line it needs to convert in the vrbl to be compared in this example is string

@dutta.marina,

The solution was for your question about text file. If you ask about PDF then, you will have to extract the PDF text in String using Read PDF Text activity and then compare using provided solution.

Thanks,
Ashok :slight_smile:

1 Like

@ashokkarale

Thank You for the solution

@Luciano_Gjinaj

Do you have an workflow for the mentioned steps.

if you want to add the differences do this steps.

  1. crate and array outside the loop
  2. whenever is false just split the part when is different
  3. add in the array, when is false

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.