Hi
I am slowly learning Ruby and working on a solution. I have huge text
files with tons of garbage and I want to extract just specific lines
including the word ‘TestPhase’.
Looking for simple solutions, just struggling with the problem.
Hi
I am slowly learning Ruby and working on a solution. I have huge text
files with tons of garbage and I want to extract just specific lines
including the word ‘TestPhase’.
Looking for simple solutions, just struggling with the problem.
Thanks in advance for advice and help.
is there a famous one-liner for this …but its not good for a learning
experience.
This is ok for starters.
File.readlines(“file.txt”).each do |line|
puts line if line =~ /TestPhase/
end
have fun
you got homework …
things to read more about:
File.read* methods
=~ (regular expresions)
I am slowly learning Ruby and working on a solution. I have huge text
files with tons of garbage and I want to extract just specific lines
including the word ‘TestPhase’.
Looking for simple solutions, just struggling with the problem.
If you only need to extract those lines the most efficient solution is
probably
fgrep TestPhase
If you want to do it in Ruby you can do
ruby -ne ‘puts $_ if /TestPhase/’
If you need to further process those lines you can do
ARGF.each |line|
if /TestPhase/ =~ line
# …
puts line
end
end
Hi
I am slowly learning Ruby and working on a solution. I have huge text
files with tons of garbage and I want to extract just specific lines
including the word ‘TestPhase’.
Looking for simple solutions, just struggling with the problem.
Hi
I am slowly learning Ruby and working on a solution. I have huge text
files with tons of garbage and I want to extract just specific lines
including the word ‘TestPhase’.
Looking for simple solutions, just struggling with the problem.
Thanks in advance for advice and help.
To reduce the array File.readlines returns to only the lines that
contain ‘TestPhase’ use