473,320 Members | 2,052 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,320 software developers and data experts.

Comparing the contents of two text files

1
I am new to Perl scripting but I need to compare a list of users in one file to a list of users in another file e.g

File A File B
B. Simpson B.Simpson
F.Flintstone F.Flintstone
D.Duck D.Duck
J. Rabbit

and I want to write to an output file any names that are in file A but not in file B.

I've tried pattern matching but that doesn't list only missing names.

Any ideas?
Feb 14 '07 #1
2 1888
@stev1e

Try this:
Expand|Select|Wrap|Line Numbers
  1. @list_1 = ( "a", "b", "c", "d" );
  2. @list_2 = ( "b", "d" );
  3.  
  4. map { $seen{$_}++ } @list_2;
  5. map { if ( ! defined($seen{$_}) ) { print $_."\n" } } @list_1;
Greetz, Doc
Feb 14 '07 #2
arne
315 Expert 100+
I am new to Perl scripting but I need to compare a list of users in one file to a list of users in another file e.g

File A File B
B. Simpson B.Simpson
F.Flintstone F.Flintstone
D.Duck D.Duck
J. Rabbit

and I want to write to an output file any names that are in file A but not in file B.

I've tried pattern matching but that doesn't list only missing names.

Any ideas?
What about
- reading the names of file B into a hash
- using the names of file A as the key to access the hash

If the name is not in the hash it has been in file A, but not in B.
Feb 14 '07 #3

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

Similar topics

6
by: Wescotte | last post by:
I'm writing a tiny php app that will log into our bank of america account and retrieve a file containing a list of checks that cleared the previous day. The problem I'm running into is when I...
4
by: ddd | last post by:
I am trying to build a diff tool that allows me to compare two HTML files. I am looking for resources on how to achive this. The main problem is that I do not want to simply highlight the line of...
6
by: Holger Kasten | last post by:
Hello, I am looking for a fast and efficient way to compare two text files and create a thrid one. E.g. Input file 1: Number 1 Number 2
4
by: lasmit | last post by:
I am updating a C# web project which stores the contents of an ASP web form in an SQL Server 2000 database. Originally the code deleted all the current contents of the database and then...
5
by: Peteroid | last post by:
I realize this might not be the correct newsgroup, but since I have a general question I need answering in the context of doing a managed VC++.NET Managed application, this is as good a place as...
0
by: richardkreidl | last post by:
I have the following hash script that I use to compare two text files. 'Class Public Class FileComparison Public Class FileComparisonException Public Enum ExceptionType U 'Unknown A 'Add...
2
by: Smithers | last post by:
I would appreciate some recommendations for programmatically determining if files differ. I'm writing a utility that backs up files that customers upload to Web sites. Rather than mindlessly...
4
by: andrewwan1980 | last post by:
I've got two websites, one original, the other based off the original. I like to diff/compare the websites using diff automatic comparison tools to see what text/information has changed. The...
3
by: erbrose | last post by:
Hello all! Newbie here, I've been tasked with a fairly intensive project here and my perl skills are still at a minimum so this post may eventually turn into a long one, but I am only going to ask...
1
by: Avi1 | last post by:
Hi, I got the code (from the internet)for comparing two files and showing the difference in contents.Now,I tried the same code for two files written in japanese language(kanji).If I save the two...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.