473,382 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Parsing two files to get matching and non-matching entries

Hello

I am required to parse two files that contain email addresses and figure out a way to get the matching and non-matching email addresses from both the files. I was able to get the matching entries by using the following code:
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. open f1,"file1" or die "cannot open file:$!\n";
  3. open f2,"file2" or die "cannot open file2:$!\n";
  4. open out,">match.out" or die $@;
  5. @file1=<f1>;
  6. @file2 =<f2>;
  7. close f1;close f2;
  8. $count=0;
  9. for($k=0;$k<$#file1;$k++)
  10. {
  11.     #print $file2[$k];
  12.     for($i=0;$i<$#file2;$i++)
  13.     {
  14.         next if(!(lc($file2[$i]) eq lc($file1[$k])));
  15.         print out lc($file1[$k]);
  16.         ++$count;
  17.  
  18.     }
  19.  
  20. }
  21. print "Match: $count entries\n";
  22. close out;    
However, I am sure this is just a quick way out to get the matching entries, as getting the whole content of a file in an array is not the way to go. I would like to be able to manipulate the filehandles as the data comes in from the two files dynamically to get the matching entries.

This is my first post to this forum. Please advise.

Thanks,
Santhosh.
Sep 19 '07 #1
2 2102
numberwhun
3,509 Expert Mod 2GB
Hello

I am required to parse two files that contain email addresses and figure out a way to get the matching and non-matching email addresses from both the files. I was able to get the matching entries by using the following code:
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. open f1,"file1" or die "cannot open file:$!\n";
  3. open f2,"file2" or die "cannot open file2:$!\n";
  4. open out,">match.out" or die $@;
  5. @file1=<f1>;
  6. @file2 =<f2>;
  7. close f1;close f2;
  8. $count=0;
  9. for($k=0;$k<$#file1;$k++)
  10. {
  11.     #print $file2[$k];
  12.     for($i=0;$i<$#file2;$i++)
  13.     {
  14.         next if(!(lc($file2[$i]) eq lc($file1[$k])));
  15.         print out lc($file1[$k]);
  16.         ++$count;
  17.  
  18.     }
  19.  
  20. }
  21. print "Match: $count entries\n";
  22. close out;    
However, I am sure this is just a quick way out to get the matching entries, as getting the whole content of a file in an array is not the way to go. I would like to be able to manipulate the filehandles as the data comes in from the two files dynamically to get the matching entries.

This is my first post to this forum. Please advise.

Thanks,
Santhosh.
I just want to clarify for my understanding. Are you trying to compare two files and produce 1 file with NO duplicate entries?

Regards,

Jeff
Sep 19 '07 #2
I just want to clarify for my understanding. Are you trying to compare two files and produce 1 file with NO duplicate entries?

Regards,

Jeff
Thanks for your quick response, Jeff.

Yes. I would like to have 1 file with NO Duplicate Entries. Also, I would like to know if there's a way to dynamically read from a filehandle during each comparison.

Thanks.
Sep 19 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
1
by: Christoph Bisping | last post by:
Hello! Maybe someone is able to give me a little hint on this: I've written a vb.net app which is mainly an interpreter for specialized CAD/CAM files. These files mainly contain simple movement...
6
by: giulianodammando | last post by:
In the development of a simple numerical simulation software i need to read some initialization parameters from a file that looks like: # Global Setup species = 1; \begin{specie}<1>...
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
7
by: Eric Wertman | last post by:
I have a set of files with this kind of content (it's dumped from WebSphere): ]
0
by: Astan Chee | last post by:
Hi, Im using pyflag to parse .pcap files. Pyflag displays the data part of the .pcap file in binary and I was wondering what this means. How do I decode the 'data' part of the packet without using...
1
by: andrewwan1980 | last post by:
I need help in parsing unicode webpages & downloading jpeg image files via Perl scripts. I read http://www.cs.utk.edu/cs594ipm/perl/crawltut.html about using LWP or HTTP or get($url) functions &...
2
by: ssaraceni | last post by:
Hi, I want to open XML files, also non well formed ones, to show the XML tags into my java application. Actually I'm using Xerces2-J to parse XML files, but if I try to open a non-well formed file,...
1
by: hd95 | last post by:
In a perfect world my xml feed source would produce perfect xml ..that is not the case I am parsing an XML feed that sometimes has ampersands and dashes in the content that messes up my parsing. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.