From: Phrogz Date: 2007-02-07T02:00:05+09:00 Subject: Re: Parse csv similar file On Feb 6, 8:36 am, Drew Olson wrote: > I think he wants to append this array with information each time he sees > the same key [...] So here's another version: lookup = Hash.new{ |h,k| h[k]=[] } DATA.each_line{ |line| line.chomp! warn "No key in '#{line}'" unless key = line[ /\bE\w+/ ] lookup[ key ] << line } p lookup[ "E050441" ] #=> ["AP850SDA;INCLIB;E050441;AP013;240107;0730", "AP850SDS;INCLIB;E050441;AP013;240107;0730"] require 'pp' pp lookup #=> {"E050441"=> #=> ["AP850SDA;INCLIB;E050441;AP013;240107;0730", #=> "AP850SDS;INCLIB;E050441;AP013;240107;0730"], #=> "E052337"=> #=> ["AP850SD$;INCLIB;E052337;AP013;240107;0730", #=> "AP850SDO;INCLIB;E052337;AP013;240107;0730"], #=> "E023889"=> #=> ["AP850KP;INCLIB;E023889;AP013;240107;0730", #=> "AP850SDI;INCLIB;E023889;AP013;240107;0730"]} __END__ AP850KP;INCLIB;E023889;AP013;240107;0730 AP850SD$;INCLIB;E052337;AP013;240107;0730 AP850SDA;INCLIB;E050441;AP013;240107;0730 AP850SDI;INCLIB;E023889;AP013;240107;0730 AP850SDO;INCLIB;E052337;AP013;240107;0730 AP850SDS;INCLIB;E050441;AP013;240107;0730