remove specific text from line

C

Collin Moore

Hi
thanks for all the help on my previous question, but now I am trying to
clean up the output of some text output.

currently I have:
[email protected]: EVENT: [LOG] *** DEBUG ACTION ***

and I'd like it to have:
110.075:DEBUG ACTION

: just for easy import into excel.

Here is the current ruby file I am working with where is looked for
lines with DEBUG and START in them.

File.open('output.txt', 'w') do |f2|
File.readlines("original.txt").each do |line|
if line =~ /DEBUG/ || line =~ /START/
f2.puts line
end
end
end

Any ideas?

thanks for your help :)
 
G

Gregory Mazurek

[Note: parts of this message were removed to make it a legal post.]

Hi
thanks for all the help on my previous question, but now I am trying to
clean up the output of some text output.

currently I have:
[email protected]: EVENT: [LOG] *** DEBUG ACTION ***

and I'd like it to have:
110.075:DEBUG ACTION

: just for easy import into excel.

Here is the current ruby file I am working with where is looked for
lines with DEBUG and START in them.

File.open('output.txt', 'w') do |f2|
File.readlines("original.txt").each do |line|
if line =~ /DEBUG/ || line =~ /START/
f2.puts line
end
end
end

Any ideas?

thanks for your help :)
why don't you gsub('Time@', '').gsub(' EVENT: [LOG] *** ', '').gsub(' ***',
'')

Greg
 
C

Caleb Clausen

Hi
thanks for all the help on my previous question, but now I am trying to
clean up the output of some text output.

currently I have:
[email protected]: EVENT: [LOG] *** DEBUG ACTION ***

and I'd like it to have:
110.075:DEBUG ACTION

: just for easy import into excel.

Here is the current ruby file I am working with where is looked for
lines with DEBUG and START in them.

File.open('output.txt', 'w') do |f2|
File.readlines("original.txt").each do |line|
if line =~ /DEBUG/ || line =~ /START/
f2.puts line
end
end
end

Any ideas?

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.)

line.sub!(/^Time@ (\d+\.\d+):.*\*{3} ([A-Z]+ [A-Z]+) \*{3}$/){ $1+':'+$2 }
 
A

Alexey Bovanenko

Hi!

I think you can use the following solution:

class TestClass
def test(val)
val.scan(/^[^@]+@(\d{1,3}\.\d{1,3})[^*]+\*{3}\s*([^*]+)/) do
puts $1+" : "+$2
end
end
end

myInst=3DTestClass.new
myInst.test("[email protected]: EVENT: [LOG] *** DEBUG ACTION ***");

The result is: 110.075 : DEBUG ACTION

Hi
thanks for all the help on my previous question, but now I am trying to
clean up the output of some text output.

currently I have:
[email protected]: EVENT: [LOG] *** DEBUG ACTION ***

and I'd like it to have:
110.075:DEBUG ACTION

: just for easy import into excel.

Here is the current ruby file I am working with where is looked for
lines with DEBUG and START in them.

File.open('output.txt', 'w') do |f2|
File.readlines("original.txt").each do |line|
=A0if line =3D~ /DEBUG/ || line =3D~ /START/
=A0 =A0 f2.puts line
=A0 end
end
end

Any ideas?

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.)

line.sub!(/^Time@ (\d+\.\d+):.*\*{3} ([A-Z]+ [A-Z]+) \*{3}$/){ $1+':'+$2 = }
 
C

Collin Moore

Alexey said:
Hi!

I think you can use the following solution:

class TestClass
def test(val)
val.scan(/^[^@]+@(\d{1,3}\.\d{1,3})[^*]+\*{3}\s*([^*]+)/) do
puts $1+" : "+$2
end
end
end

myInst=TestClass.new
myInst.test("[email protected]: EVENT: [LOG] *** DEBUG ACTION ***");

The result is: 110.075 : DEBUG ACTION

I tried this and 110.075 : DEBUG ACTION repeats for all the lines in the
output.
 
A

Alexey Bovanenko

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

Alexey said:
Hi!

I think you can use the following solution:

class TestClass
=A0 def test(val)
=A0 =A0 val.scan(/^[^@]+@(\d{1,3}\.\d{1,3})[^*]+\*{3}\s*([^*]+)/) do
=A0 =A0 =A0 puts $1+" : "+$2
=A0 =A0 end
=A0 end
end

myInst=3DTestClass.new
myInst.test("[email protected]: EVENT: [LOG] *** DEBUG ACTION ***");

The result is: 110.075 : DEBUG ACTION

I tried this and 110.075 : DEBUG ACTION repeats for all the lines in the
output.
 
C

Collin Moore

Caleb said:
: just for easy import into excel.
end

Any ideas?

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.)

line.sub!(/^Time@ (\d+\.\d+):.*\*{3} ([A-Z]+ [A-Z]+) \*{3}$/){ $1+':'+$2
}

I tried this with

File.open('output.txt', 'w') do |f2|
File.readlines("original.txt").each do |line|
if line =~ /DEBUG/ || line =~ /START/
f2.puts line.sub!(/^Time@ (\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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top