From: w_a_x_man@... Date: 2009-02-07T01:09:26+09:00 Subject: Re: Question - looking for library to use for query like code? On Feb 6, 8:32 am, Mmcolli00 Mom wrote: > Can this be done with Ruby? (this may be a shot in the dark) > > Say you have a text file with a lot of data and you want to group all of > your data by a specific value. Is there a way to code something in ruby > similar to a query that you would create using sql. Can this even be > done using Ruby? And if so, is there a library that you can refer me to? > If not, do you know any alternative ways? Thanks, MC > > example of text: > > auto, model > car, honda > truck, chevy > car, nissan > truck, toyota > truck, ford > > how i'd like it to look: > > car, honda, nissan, > truck, chevy, toyota, ford > -- > Posted viahttp://www.ruby-forum.com/. data = Hash.new {|h,k| h[k] = []} IO.foreach("myfile.txt"){|line| type, make = line.strip.split( / *, */ ) data[ type ] << make } p data