I'm tring to compare two files and get the equal data.
So for example I have this file (file1.txt):
1173|0040
1174|052425
1175|052634
1176|053281
1177|055876
1188|2222
1189|2002
1190|2002
1191|2002
And file2.txt file:
000|20019|0040|No Definida.
000|20034|052425|No Definida.
000|20014|052634|No Definida.
000|20031|053281|No Definida.
000|20044|055876|No Definida.
000|67022|2000|No Definida.
000|67022|2000|No Definida.
000|00019|2000|No Definida.
000|67024|2000|No Definida.
210|72059|2002|SERGIO SUAREZ LLAMAS
210|72059|2002|SERGIO SUAREZ LLAMAS
210|72059|2002|SERGIO SUAREZ LLAMAS
210|20023|2002|SERGIO SUAREZ LLAMAS
210|72057|2002|SERGIO SUAREZ LLAMAS
210|67013|2002|SERGIO SUAREZ LLAMAS
So that in the second column of the file1.txt and third column of the file2.txt is the data that could be equal, I want to compare
and get it in a new file. And I don't have idea how to do it.
My original idea was first, get the columns that are equal, for example file1.txt and file2.txt :
foreach my $line (@fuente) {
my @parts = split /\|/, $line;
print join("|", @parts[2]), "\n";
}
foreach my $line (@fuente2) {
my @parts = split /\|/, $line;
print join("|", @parts[3]), "\n";
}
But I don't know how to compare the files
Best regards.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.