File compare and remove lines

Here is my issue:

I have two files - call them big.txt and small.txt. My goal is to have
a list file and remove any lines in the big file that exist.

Big.txt is a tab del file with the following info

11 Fred Flinestone Bedrock,Il
12 Wilma Flinestone Bedroc, Il

small.txt is a tab del file - following information
12
23
32
23

I would like to scan big.txt against small.txt to get a final file
good.txt - with the following

11 Fred Flinestone Bedrock,Il

regards,

matt

On Aug 22, 2006, at 4:27 PM, Matt Coffman wrote:

I would like to scan big.txt against small.txt to get a final file
good.txt - with the following

11 Fred Flinestone Bedrock,Il

Which part are you hung up on? We’ll help get you unstuck.

James Edward G. II

James G. wrote:

On Aug 22, 2006, at 4:27 PM, Matt Coffman wrote:

I would like to scan big.txt against small.txt to get a final file
good.txt - with the following

11 Fred Flinestone Bedrock,Il

Which part are you hung up on? We’ll help get you unstuck.

James Edward G. II

Actually the entire thing - I am currently using VEDIT to work through
this. I am a newbie to Ruby and wanted to give it a shot. Thanks in
advance

Matt

On Aug 22, 2006, at 4:45 PM, Matt Coffman wrote:

James Edward G. II

Actually the entire thing - I am currently using VEDIT to work through
this. I am a newbie to Ruby and wanted to give it a shot. Thanks in
advance

So you are asking us to write it for you? How is that you deciding
to give Ruby a shot? :wink:

James Edward G. II

James G. wrote:

On Aug 22, 2006, at 4:45 PM, Matt Coffman wrote:

James Edward G. II

Actually the entire thing - I am currently using VEDIT to work through
this. I am a newbie to Ruby and wanted to give it a shot. Thanks in
advance

So you are asking us to write it for you? How is that you deciding
to give Ruby a shot? :wink:

James Edward G. II

Currently reading “Learn to Program” C.Pine

Not exactly - just looking for guidance - :slight_smile:

bad = []
File.read(“small.txt”).each { |line| bad << line.to_i }
good = File.new(“good.txt”,“w”);
File.read(“big.txt”).each do |line|
id = line.split(’\t’)[0].to_i
good << line unless bad.delete(id)
end
good.close

I’m sure there’s a better way, but this took only two minutes to write.
Max

Matt Coffman wrote:

James Edward G. II

Actually the entire thing - I am currently using VEDIT to work through
this. I am a newbie to Ruby and wanted to give it a shot.

Give what a shot? When you go on a bear hunt, do you tell someone else
to go
get the bear for you, while you wait in the lounge?

Your first post specified this goal:

I have two files - call them big.txt and small.txt. Â My goal is to have
a list file and remove any lines in the big file that exist.

Is that your goal or a goal for your alter ego, who is now out looking
for a
suitable bear?

Thanks in advance

You are welcome in advance.

People learn to write computer programs primarily by writing computer
programs, not by asking other people to write them.

You need to realize that those with some Usenet experience, when reading
a
message like yours, instinctively ask themselves, “Is this someone
trying
to avoid doing his own homework?”

In order to become as rich as, say, Bill Gates, you must first learn how
to
write computer programs. Remember that Bill Gates once actually wrote
computer programs, by himself, and he was rather good at it. He didn’t
ask
someone else to do the programming (at least, not at first).

My goal is to have
a list file and remove any lines in the big file that exist.

… and a good first step would be to specify the problem with perfect
clarity.

Please understand that people on this newsgroup would leap at the chance
to
help someone who is sincerely trying to learn Ruby. All we need is a
sign
that you are sincere.

On Aug 22, 2006, at 5:09 PM, Matt Coffman wrote:

advance

So you are asking us to write it for you? How is that you deciding
to give Ruby a shot? :wink:

James Edward G. II

Currently reading “Learn to Program” C.Pine

Not exactly - just looking for guidance - :slight_smile:

Oh great. I can do that. Here’s the steps I might try:

  1. Read the small file into an Array
  2. Write a loop that reads each line of the big file and prints it out
  3. Modify the loop not to print things in the Array

See if that gets you going and do come back if you get stuck!

James Edward G. II

Matt Coffman wrote:

So you are asking us to write it for you?
Not exactly - just looking for guidance - :slight_smile:

Okay, here’s some guidance.

Chances are Ruby will be able to perform the task you describe, once you
describe it with sufficient clarity, and once you acquire the necessary
programming skill, step by step, patiently and persistently.

We’ll know you are on track to solve the problem when you start a post
with
“here’s my code so far … and here’s what happened when I ran it …”

Paul L. wrote:

Matt Coffman wrote:

So you are asking us to write it for you?
Not exactly - just looking for guidance - :slight_smile:

Okay, here’s some guidance.

Chances are Ruby will be able to perform the task you describe, once you
describe it with sufficient clarity, and once you acquire the necessary
programming skill, step by step, patiently and persistently.

We’ll know you are on track to solve the problem when you start a post
with
“here’s my code so far … and here’s what happened when I ran it …”

Again, thank you for the lecture. No need to respond! poumpous ass!

Matt Coffman wrote:

As stated in my last post - I was looking for guidance. My sincere
apologies if it appears I am looking for someone to code for me. I am
new to this and I obviously lack certain skills - communicating my
problem being one of them. I appreciate your candid response but I
don’t think the lecture is necessary.

Oh, but it was. Now you know that you need to show your sincerity by
posting
your code and your questions about your code. You didn’t know that
before.
You are way ahead, and the next steps are yours.

Steps like these:

  1. Describe the problem to be solved with perfect clarity, such that no
    typical reader could possibly have any doubt about the problem to be
    solved. One way to do this is to say “Here is sample content for the
    first
    file … and the second file … and here is what the program’s output
    should look like …”

  2. Show us that you intend to get personally involved by posting your
    code.
    If you cannot post code, post pseudo-code, that is to say, “code” meant
    to
    resemble steps toward solving the problem, even if the “code” isn’t
    actually executable.

As stated in my last post - I was looking for guidance.

This is the right guidance. You asked, and now you have it.

We await your reply.

Paul L. wrote:

Matt Coffman wrote:

James Edward G. II

Actually the entire thing - I am currently using VEDIT to work through
this. I am a newbie to Ruby and wanted to give it a shot.

Give what a shot? When you go on a bear hunt, do you tell someone else
to go
get the bear for you, while you wait in the lounge?

Your first post specified this goal:

I have two files - call them big.txt and small.txt. My goal is to have
a list file and remove any lines in the big file that exist.

Is that your goal or a goal for your alter ego, who is now out looking
for a
suitable bear?

Thanks in advance

You are welcome in advance.

People learn to write computer programs primarily by writing computer
programs, not by asking other people to write them.

You need to realize that those with some Usenet experience, when reading
a
message like yours, instinctively ask themselves, “Is this someone
trying
to avoid doing his own homework?”

In order to become as rich as, say, Bill Gates, you must first learn how
to
write computer programs. Remember that Bill Gates once actually wrote
computer programs, by himself, and he was rather good at it. He didn’t
ask
someone else to do the programming (at least, not at first).

My goal is to have
a list file and remove any lines in the big file that exist.

… and a good first step would be to specify the problem with perfect
clarity.

Please understand that people on this newsgroup would leap at the chance
to
help someone who is sincerely trying to learn Ruby. All we need is a
sign
that you are sincere.

As stated in my last post - I was looking for guidance. My sincere
apologies if it appears I am looking for someone to code for me. I am
new to this and I obviously lack certain skills - communicating my
problem being one of them. I appreciate your candid response but I
don’t think the lecture is necessary.

On Wed, Aug 23, 2006 at 07:45:10AM +0900, Paul L. wrote:

Has it occurred to you that you would refuse to accept your own attitude and
language if you received it from another?

All I can say for sure at this stage is that you are very young, and you
have no behavioral reserves to speak of.

Try to return to the original topic. Thanks!

Frankly, I wonder if maybe you both couldn’t use some advice on mailing
list etiquette.

Matt Coffman wrote:

We’ll know you are on track to solve the problem when you start a post
with
“here’s my code so far … and here’s what happened when I ran it …”

Again, thank you for the lecture. No need to respond! poumpous ass!

You’ve just gone over to the dark side, and you have yet to meaningfully
address the problem you originally posted about.

Has it occurred to you that you would refuse to accept your own attitude
and
language if you received it from another?

All I can say for sure at this stage is that you are very young, and you
have no behavioral reserves to speak of.

Try to return to the original topic. Thanks!

In order to become as rich as, say, Bill Gates, you must first
learn how
to
write computer programs. Remember that Bill Gates once actually wrote
computer programs, by himself, and he was rather good at it. He
didn’t
ask
someone else to do the programming (at least, not at first).

Yes, but in order to become as rich as someone as, say, Steve
Ballmer, you’re free to have someone like Bill Gates do the
programming for you (even at first). :slight_smile:

Matthew

Matthew J.son wrote:

In order to become as rich as, say, Bill Gates, you must first
learn how
to
write computer programs. Remember that Bill Gates once actually wrote
computer programs, by himself, and he was rather good at it. He
didn’t
ask
someone else to do the programming (at least, not at first).

Yes, but in order to become as rich as someone as, say, Steve
Ballmer, you’re free to have someone like Bill Gates do the
programming for you (even at first). :slight_smile:

Matthew

My sincere apologies to all.

Matt

Carlos wrote:

Matt Coffman wrote:

My sincere apologies to all.

Matt

Where to can we redirect newbies asking for help, before people start to
spit rude answers to them and discourage them to learn Ruby (or to let
us help them to learn Ruby)? Is there any ruby-newby mailing
list/newsgroup?

AFAIK there is only this one Ruby NG, and I agree it might be better if
there were two or more, for specific needs. A symptom indicating this
need
(apart from what you point out) is the rather high volume of posts to
this
one NG, on diverse subjects related to Ruby.

But I must say the OP would have gotten the same reception from a Ruby
NG
geared to newbies … he would eventually be asked to post some code. So
the outcome would have been the same.

Matt Coffman wrote:

My sincere apologies to all.

Matt

Where to can we redirect newbies asking for help, before people start to
spit rude answers to them and discourage them to learn Ruby (or to let
us help them to learn Ruby)? Is there any ruby-newby mailing
list/newsgroup?

How about this (heh, just discovered File#readlines!):


#!/usr/bin/ruby -w

skip = Hash.new

File.readlines(ARGV.shift).each do |line|
skip[line.chomp.strip] = 1
end

File.readlines(ARGV.shift).each do |line|
print line unless skip[line.match(/^\s*(\d+)/)[1]]
end

On Wednesday 23 August 2006 09:18 am, Carlos wrote:

Matt Coffman wrote:

My sincere apologies to all.

Matt

Where to can we redirect newbies asking for help, before people start to
spit rude answers to them and discourage them to learn Ruby (or to let
us help them to learn Ruby)? Is there any ruby-newby mailing
list/newsgroup?

I know of no Ruby-Newbie mailing lists or newsgroups, but there are many
Ruby
tutorials on the web. I’ve created one here:

As far as rude answers, a newbie question is no excuse for rudeness.
It’s so
much easier simply to not answer the newbie question, or to have a stock
signature block that, in the nicest way possible, says RTFM and tells
the
newbie where the fantastic manual resides.

SteveT

Steve L.
Author:

  • Universal Troubleshooting Process courseware
  • Troubleshooting Techniques of the Successful Technologist
  • Manager’s Guide to Technical Troubleshooting
  • Twenty Eight Tales of Troubleshooting
  • Rapid Learning: Secret Weapon of the Successful Technologist