Solved

Compare 2 Lists

Posted on 2013-11-14
10
173 Views
Last Modified: 2013-11-14
I need to take two text files. One has one column of data, one word per line. The second one has a number of words per line, but the first line (separated by white space) is the only thing I am interested in removing any lines that do not have "DD" in the word. I would like to print a list of any words that appear in 1.txt that do not appear in 2.txt. They might be in any order, and might appear any number of times. Is there an easy way of doing this?

Examples:

1.txt:
test
DDblah
DDblahBlah

2.txt:
testtest
DDBlahblah

Result:
DDblah

Since the only work that has DD in it, that appears in 1.txt that does not appear in 2.txt is DDblah, only DDlah would be printed.
0
Comment
Question by:stakor
  • 7
  • 3
10 Comments
 

Author Comment

by:stakor
ID: 39650033
Sorry, 2.txt should read:

testtest gibberish gibberish
DDBlahblah gibberish gibberish gibberish
0
 
LVL 84

Expert Comment

by:ozo
ID: 39650058
I'm confused.
first line (separated by white space)
Do you mean the first word  (separated by white space)?
but the first line (separated by white space) is the only thing I am interested in removing any lines that do not have "DD" in the word.
Does the I am interested in go with is the only thing am interested in or does it go with I am interested in removing any lines?

is
DDblahBlah
the same as
DDBlahblah
?
Do you want to ignore case?


Do you mean you want to do something like:
perl -d -alne '$x{lc $1}|=$#ARGV if /^(DD\S*)/;END{$x{$_}==0 and print for keys %x}' 1.txt 2.txt
0
 

Author Comment

by:stakor
ID: 39650062
Sorry for the mistake. The first word is what I was trying to say.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:stakor
ID: 39650064
And case should be ignored as well.
0
 

Author Comment

by:stakor
ID: 39650072
Is there a way to run this without invoking a database mode? I know that would probably the most efficient, but this will likely only be a list of like 50 - 100 items.
0
 

Author Comment

by:stakor
ID: 39650073
The reason I ask, is that when I ran it, I was in an interactive mode of some variety.
0
 
LVL 84

Expert Comment

by:ozo
ID: 39650091
What is a database mode?
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 39650095
Oops, forgot to turn off debugging when I cut and pasted.
The command should have been.

perl -alne '$x{lc $1}|=$#ARGV if /^(DD\S*)/;END{$x{$_}==0 and print for keys %x}' 1.txt 2.txt
0
 

Author Comment

by:stakor
ID: 39650099
When I ran the script, I was sitting at a command prompt that read something like DB1 ? I did not write it down.
0
 

Author Comment

by:stakor
ID: 39650135
I think I figured it out.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl for loop for 2000 ms 7 100
Port 80 requests 16 95
Perl string replace for refred url 9 62
what are these modules in perl script 4 99
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question