Comparing and sorting file contents by line

(imported topic written by zzmhn991)

How would you compare the contents of two files to see which is equal to another based off of line values?

Such as input.txt and output.txt as…

Q: lines of file “c:\output.txt”

Q: lines of file “c:\input.txt”

How can you compare the two files and then report the lines of the file that are equal?

Example =

output.txt would contain:

10.10.10.1

10.10.10.15

10.10.10.121

10.10.10.130

10.10.10.5

input.txt would contain:

10.10.10.1

10.10.10.16

10.10.10.124

10.10.10.132

10.10.10.5

Therefore after comparing the lines of each file the output of equal values would report: 10.10.10.1 and 10.10.10.5.

Can this be done with the lines statement or is there another approach in comparing two files and their contents?

Thank you.

(imported comment written by Lee Wei)

zzmhn9,

This should work, please give it a try.

q: (lines of file “c:\temp\input.txt”, lines of file “c:\temp\output.txt”)

A: 10.10.10.1, 10.10.10.1

A: 10.10.10.1, 10.10.10.15

A: 10.10.10.1, 10.10.10.121

A: 10.10.10.1, 10.10.10.130

A: 10.10.10.1, 10.10.10.5

A: 10.10.10.16, 10.10.10.1

A: 10.10.10.16, 10.10.10.15

A: 10.10.10.16, 10.10.10.121

A: 10.10.10.16, 10.10.10.130

A: 10.10.10.16, 10.10.10.5

A: 10.10.10.124, 10.10.10.1

A: 10.10.10.124, 10.10.10.15

A: 10.10.10.124, 10.10.10.121

A: 10.10.10.124, 10.10.10.130

A: 10.10.10.124, 10.10.10.5

A: 10.10.10.132, 10.10.10.1

A: 10.10.10.132, 10.10.10.15

A: 10.10.10.132, 10.10.10.121

A: 10.10.10.132, 10.10.10.130

A: 10.10.10.132, 10.10.10.5

A: 10.10.10.5, 10.10.10.1

A: 10.10.10.5, 10.10.10.15

A: 10.10.10.5, 10.10.10.121

A: 10.10.10.5, 10.10.10.130

A: 10.10.10.5, 10.10.10.5

q: (lines of file “c:\temp\input.txt”, lines of file “c:\temp\output.txt”) whose (item 0 of it = item 1 of it)

A: 10.10.10.1, 10.10.10.1

A: 10.10.10.5, 10.10.10.5

q: (item 0 of it) of (lines of file “c:\temp\input.txt”, lines of file “c:\temp\output.txt”) whose (item 0 of it = item 1 of it)

A: 10.10.10.1

A: 10.10.10.5

Lee Wei

(imported comment written by len123)

Hi,

I have a similar question. I need to compare contents of two configuration files. the files look like:

STANDARDFILE.TXT

parameter1=123

parameter2=1234

parameter11=abc

myparameter12=a

CURRENTFILE.TXT

parameter1=1234

myparamter12=a

parameter11=abc

parameter2=1

I want to compare the currentfile.txt against the standard.txt. the order of the parameters may not necessarily be the same or some may be missing. I would want to compare and get a true if the values of each parameter between the files are present and equal; and show any of the parameters that are different.

so i would compare the value of parameter1 from the current file.txt against the value of parameter1 from the standard.txt file and so on.

Thanks!

(imported comment written by len123)

Hi to followup…i forgot to mention…the files has more than 100 parameters

i have tried the following but getting errors. Also wanted to find out if there is a better way of doing it to avoid enumerating all the parameters

if ((((it as trimmed string) of following text of last “=” of lines whose (it as trimmed string as lowercase equals “parameter1”) of preceding text of file “c:\temp\currentfile.txt”) of file “c:\temp\currentfile.txt”) equals (((it as trimmed string ) of following text of last “=” of lines whose (it as trimmed string as lowercase equals “parameter1”) of preceding text of file “c:\temp\standardfile.txt”) of file “c:\standardfile.txt”)) then ((((it as trimmed string) of following text of last “=” of lines whose (it as trimmed string as lowercase equals “parameter2”) of preceding text of file “c:\temp\currentfile.txt”) of file “c:\temp\currentfile.txt”) equals (((it as trimmed string ) of following text of last “=” of lines whose (it as trimmed string as lowercase equals “parameter2”) of preceding text of file “c:\temp\standardfile.txt”) of file “c:\standardfile.txt”)) else (false)

THANKS

(imported comment written by zzmhn991)

Thank you!