You want a regexp. Something like this should work. (Stick it in
before the puts line.) (You may need to customize depending on your
exact requirements.)
It’s because I put line myInst.test(“[email protected]: EVENT: [LOG] ***
DEBUG ACTION ***”);
There’s string literal: “[email protected]: EVENT: [LOG] *** DEBUG ACTION
***”
If you want parse file content you must read lines and put it to method:
File.open(“fname.txt”).each do |line|
myInst.test(line)
end
You want a regexp. Something like this should work. (Stick it in
before the puts line.) (You may need to customize depending on your
exact requirements.)
File.open(‘output.txt’, ‘w’) do |f2|
File.readlines(“original.txt”).each do |line|
if line =~ /DEBUG/ || line =~ /START/
f2.puts line.sub!(/^[email protected] (\d+.\d+):.**{3} ([A-Z]+ [A-Z]+)
*{3}$/){ $1+’:’+$2 }
end
end
end
and I get the output.txt with nil for each positive match.