I have two files large files:
1) file1.txt as below: ( more than 20,000 records )

5020120475      |13ZJ38000813                  |20141204|R
5020127431      |13ZJ38001569                  |20141201|R
5020127689      |12ZJ44000606                  |20141203|R
5020127728      |13ZJ38001356                  |20141203|R
5020127956      |13ZJ62002544                  |20141205|R
5020127972      |13ZJ49000082                  |20141205|R
5020128325      |13ZJ57000785                  |20141210|R
5020128706      |13ZJ38002805                  |20141211|R
5020129084      |10XJ70107764                  |20141217|R
5020129102      |12ZJ54000041                  |20141217|R


2) other file as file2.txt as below: ( more than 2,00,000 records )


and I need expexted output as below:

5020129084      |10XJ70107764                  |20141217|R
5020129102      |12ZJ54000041                  |20141217|R

NOTE: it will compare first file of 2nd column and second file of ist column and print the compare records of ist file as above.

Many thanks for help in Perl or unix awk.

Sorry, but we don't do your work for you. Make an effort to code this in the language of your preference and then we can help.

Hi rantnna,

It is quite easy to compare two or more files in Perl. In fact, if you have taken your time to filter through theis forum, you will disccover that that has been done times and again.

However, since you have several data you might consider using database, not that Perl can't handle it but I think I will be a lot better especially if you don't have so much RAM to play with.

That said, what you can do is this:

open the first file and read in your data row after row into an hash using the second column has your key.

Then open the second file and step through it, compare each key in your hash with each row of the second file. If there is a match then print out the hash values for which the key matched.

So, "we" expect to see your code since you now have a prototype in words what you need to do. Of course, you can do it!

This article has been dead for over six months. Start a new discussion instead.