Work on pipe seperated log file

Hi,
     I have a pipe seperated txt file, i need to read the data and work
on it.
Data looks like this:
file
test1|acount1|emp1
test2|acount2|emp2
test3|acount3|emp3
test4|acount4|emp4

when i say emp3, it should display 'test3' value and so on.

···

--
Posted via http://www.ruby-forum.com/.

You can use File#foreach to iterate over the lines of the file,
String#split to divide each line in parts, and a Hash or other data
structure to store things for later querying.

Jesus.

···

On Wed, Jun 6, 2012 at 7:54 AM, ideal one <lists@ruby-forum.com> wrote:

Hi,
I have a pipe seperated txt file, i need to read the data and work
on it.
Data looks like this:
file
test1|acount1|emp1
test2|acount2|emp2
test3|acount3|emp3
test4|acount4|emp4

when i say emp3, it should display 'test3' value and so on.

You can use CSV and put data in a Hash. This should get you started:

$ ruby19 -r csv -e 'CSV.new(ARGF, col_sep:"|").each{|r| p r}' <<CSV
test1|acount1|emp1
test2|acount2|emp2
test3|acount3|emp3
test4|acount4|emp4
CSV
["test1", "acount1", "emp1"]
["test2", "acount2", "emp2"]
["test3", "acount3", "emp3"]
["test4", "acount4", "emp4"]

Kind regards

robert

···

On Wed, Jun 6, 2012 at 7:54 AM, ideal one <lists@ruby-forum.com> wrote:

Hi,
I have a pipe seperated txt file, i need to read the data and work
on it.
Data looks like this:
file
test1|acount1|emp1
test2|acount2|emp2
test3|acount3|emp3
test4|acount4|emp4

when i say emp3, it should display 'test3' value and so on.

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/