From: Garthy D Date: 2012-06-07T16:15:29+09:00 Subject: Re: Parsing pipe delimited text file & storing in arrays Hi, Personally, I'd loop over each line of the file (see "gets"), and you're probably going to want your argument to "split" to be a pipe ("|") rather than a comma (","). I would avoid complex expressions, opting instead to break things up into simpler steps, until you are more comfortable with the environment. I hope this helps. Good luck! :) Garthy On 07/06/12 10:33, ideal one wrote: > Hi, > I have a txt file with pipe delimited as show below. > > An example log file is: > test1|table1|chair1|55.00 > test2|table2|chair2|155.00 > test3|table3|chair3|55.50 > test1|table4|chair4|47.75 > > i want to parse this txt file and my expected out should be > > (i) Total Cost of test1 = 55.00 + 47.75 > (ii) test1 possessed chair1 and chair4 > > How do i achieve this in ruby code, i tried but doing it as array but > how can i add up the price what 'test1' is responsible to pay? > > array = File.read("pipetest.txt").split(",").map(&:strip) > > puts array[1,2] >