I have two text files a.txt that contains data like
abcd = 4.0
def =2.0
jkl= 8.0
and b.txt which has similar data
abcd = 6.0
dfg = 2.0
jkl = 8.0

i want two compare and print the following points in a new text file

1.the names first, if they match the values they hold are matching or not
2. the names that are not matching

Recommended Answers

All 4 Replies

You could read the first file in and save the data in a hash (using the name as key and point as value). While you read the second file in, check if the key exists in the hash. If exists, compare the value which should be satisfied your #1. If not exists, it is satisfied your #2.

I'm not able to separate the data.. the example i gave is a small one only.. originally I have log data that has more than 2000 over lines of data

Hi Anirudh1,
Please can you show us what you have been able to do.
All you need do is use open function, read in the first file into an hash and then read in the second file and compare, just like Taywin had previously mentioned.
The lenght of your file had nothing to do with the code you have not presented.
Atleast use the few lines of dataset you presented here.

Can you confirm if if the names = values are unique? For example, does the name repeat itself? Do you need to store it twice or more if it is found?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.