From: Tanushree Bhoi Date: 2006-05-26T17:59:13+09:00 Subject: Re: help regarding extracting a particular value in a file ------=_Part_103258_30586921.1148633939964 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi Nuralanur Thanks for your reply and help. My data.txt file contains data like p1,p2,p3 c1,c2,c3 I did try your code.Its giving output p2 c2 but i want to retrieve a single value like p2(2nd value of 1st row ) or c3 (3rd value of 2nd row)only. Thanks in advance Tanushree On 5/26/06, Nuralanur@aol.com wrote: > > Assuming that your data is in a file "data_to_split.txt" in the same > directory, > you can do this: > > > > file_name=3D"data_to_split.txt" > data_array=3DIO.readlines(file_name) # reads content of file into an Ar= ray > ( > each entry =3D one line) > only_second_entries=3D[] > data_array.each{|line| > only_second_entries<<(line.split(',')[1]) # note that indices start at = 0 > in > Ruby > } > p 'only second entries contains' > p only_second_entries > > If you have more complicated patterns that separate your data than just a > comma, > you can also use split in conjunction with "regular expressions". > > only_second_entries<<(line.split(/,/)[1]) # note that indices > start at 0 in Ruby > > These "regular expressions" allow to search for things like "a comma and > then two small letters, followed by at least three numbers and then > anything but > "A"", so there is > room for arbitrary complexity ... > Regular expressions are explained in detail here: > > _http://www.regular-expressions.info/_ ( > http://www.regular-expressions.info/) > > Best regards, > > Axel > > > --=20 Thanks & Regards Tanushree Bhoi Software Engineer applabs Technologies e-mail : tanushree.bhoi@applabs.com :tanushree.bhoi@gmail.com ------=_Part_103258_30586921.1148633939964--