Search code examples
rubyiointerpreterirblogparser

Assign text from file to variable in Ruby without returning text


I am trying to parse some access logs with Ruby, the file itself is 363MB. I'm working in IRB and when I try to assign the text from the document to a variable data = logs.read it begins returning all the text into the interpreter, which at 363MB is an issue.

How do I assign the contents of a file to a variable without returning the value back in the interpreter?


Solution

  • Start your irb as below :

    irb --simple-prompt --noecho

    • --simple-prompt is to get the IRB prompt as >>
    • --noecho is to off the echo on IRB

    Here is an example:

    C:\>irb --simple-prompt
    >> x = 2
    => 2
    >> exit
    
    C:\>irb --simple-prompt --noecho
    >> x = 2
    >>