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)
If you only need to extract those lines the most efficient solution is probably
fgrep TestPhase <your files>
If you want to do it in Ruby you can do
ruby -ne 'puts $_ if /TestPhase/' <your files>
If you need to further process those lines you can do
ARGF.each |line|
if /TestPhase/ =~ line
# ...
puts line
end
end
There are probably plenty other options.
Kind regards
robert
···
On 10/08/2009 10:15 PM, Collin Moore wrote:
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.
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
On Fri, 09 Oct 2009 21:35:11 +0900, Rüdiger Bahns wrote:
Collin Moore schrieb:
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
File.readlines('file.txt').grep /TestPhase/
--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/