[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

file compare and remove lines

Matt Coffman

8/22/2006 9:28:00 PM

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

--
Posted via http://www.ruby-....

19 Answers

James Gray

8/22/2006 9:42:00 PM

0

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

Matt Coffman

8/22/2006 9:45:00 PM

0

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

--
Posted via http://www.ruby-....

James Gray

8/22/2006 9:56:00 PM

0

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

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

Max Muermann

8/22/2006 10:04:00 PM

0

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

On 8/23/06, Matt Coffman <matt@binarybrain.net> wrote:
> 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
>
> --
> Posted via http://www.ruby-....
>
>

Matt Coffman

8/22/2006 10:10:00 PM

0

James Gray wrote:
> On Aug 22, 2006, at 4:45 PM, Matt Coffman wrote:
>
>>> 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

Currently reading "Learn to Program" C.Pine

Not exactly - just looking for guidance - :)

--
Posted via http://www.ruby-....

Paul Lutus

8/22/2006 10:20:00 PM

0

Matt Coffman wrote:

> James Gray 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 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.

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.

--
Paul Lutus
http://www.ara...

Paul Lutus

8/22/2006 10:27:00 PM

0

Matt Coffman wrote:

> James Gray wrote:
>> On Aug 22, 2006, at 4:45 PM, Matt Coffman wrote:
>>
>>>> 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?

> Not exactly - just looking for guidance - :)

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 Lutus
http://www.ara...

Matt Coffman

8/22/2006 10:28:00 PM

0

Paul Lutus wrote:
> Matt Coffman wrote:
>
>>> 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.
>
> 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.

--
Posted via http://www.ruby-....

James Gray

8/22/2006 10:29:00 PM

0

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

> James Gray wrote:
>> On Aug 22, 2006, at 4:45 PM, Matt Coffman wrote:
>>
>>>> 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
>
> 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

Matt Coffman

8/22/2006 10:35:00 PM

0

Paul Lutus wrote:
> Matt Coffman wrote:
>
>>> So you are asking us to write it for you?
>> Not exactly - just looking for guidance - :)
>
> 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!

--
Posted via http://www.ruby-....