file compare and remove lines

M

Matt Coffman

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
 
J

James Edward Gray II

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 Gray II
 
M

Matt Coffman

James said:
Which part are you hung up on? We'll help get you unstuck.

James Edward Gray 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
 
J

James Edward Gray 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? ;)

James Edward Gray II
 
M

Max Muermann

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
 
M

Matt Coffman

James said:
So you are asking us to write it for you? How is that you deciding
to give Ruby a shot? ;)

James Edward Gray II

Currently reading "Learn to Program" C.Pine

Not exactly - just looking for guidance - :)
 
M

Matt Coffman

Paul said:
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:


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


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).


... 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.
 
J

James Edward Gray II

Currently reading "Learn to Program" C.Pine

Not exactly - just looking for guidance - :)

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 Gray II
 
M

Matt Coffman

Paul said:
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!
 
C

Chad Perrin

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!

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

Matthew Johnson

In order to become as rich as, say, Bill Gates, you must 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). :)

Matthew
 
M

Matt Coffman

Matthew said:
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). :)

Matthew

My sincere apologies to all.

Matt
 
C

Carlos

Matt said:
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?

--
 
S

Steve Litt

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:

http://www.troubleshooters.com/codecorn/ruby/basictutorial.htm

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 Litt
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

http://www.troubleshooters.com/bookstore
http://www.troubleshooters.com/utp/tcourses.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top