From: Li Chen Date: 2006-11-05T02:18:00+09:00 Subject: Re: How could I do this search using .scan - I am a newbie Kevin Stolt wrote: > Thx for ur help....but this is just searching for 'rat' isn't it? > thats not going to work> > > what I am looking is to find anything in the second column. I am not > sure how to explain otherwise..... >>> I am new to ruby and I have been search and pulling my hair to do this >>> using .scan? >>> >>> I have file which contains.....(this is an example) >>> >>> bat rat cat mat pat >>> mat sat put tomorrow today >>> I assume you read a big file called test.txt with many lines in this format ... A B C D E F... 1 2 3 4 5 6 ... 11 22 33 44 55 66 ... ... Each line is separated with \t (or whatever) Then you want to get everything from the second cloumn such as B 2 22,.. and put them to screen Here we go: ###file_read1.rb require 'enumerator' file_name='test.txt' result=Array.new ##append second column into an array File.open(file_name).each do |line| result <ruby read_file1.rb 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 >Exit code: 0 ########test.txt####### A 1 C D E F 1 2 3 4 5 6 a 3 c d e f A 4 C D E F 1 5 3 4 5 6 a 6 c d e f A 7 C D E F 1 8 3 4 5 6 a 9 c d e f A 10 C D E F 1 11 3 4 5 6 a 12 c d e f A 13 C D E F 1 14 3 4 5 6 a 15 c d e f A 16 C D E F 1 17 3 4 5 6 a 18 c d e f A 19 C D E F ####### What is the differnce between Perl and Ruby? In Perl you need to do many things by yourself but in Ruby you just tell it what you want and Ruby does it for you :) Li -- Posted via http://www.ruby-forum.com/.