INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

i want to grep expected output between two string in patter?

i want to grep expected output between two string in patter?

i want to grep expected output between two string in patter?

(OP)
set output "omppclb> error: fialed due to mismatch of values
                       Existed value : 20000
                        expected value: 40000
                        omppclb>"
from above veriable i wanted to get string between  "omppclb "
can you please suggest me how to fetch the string between that?

RE: i want to grep expected output between two string in patter?

Try this:
# this is your string
set x {omppclb> error: fialed due to mismatch of values Existed value : 20000 expected value: 40000 omppclb>}

# set variable to hold everything in between omppclb> and omppclb>:
set inBetween ""

# get your data:
regexp {omppclb>([^<]*)omppclb>} $x n inBetween

#print your result
puts $inBetween

RE: i want to grep expected output between two string in patter?

(OP)
no sir..
your solution not working

SHRIKANT BADIGER
SJCE MYSORE

RE: i want to grep expected output between two string in patter?

I'm not sure if your string is on single line or on multiple lines.
For the latter case use -lineanchor option in regexp

This works for me in both cases:

CODE

# matching single line string
set output "omppclb> error: fialed due to mismatch of values Existed value : 20000 expected value: 40000 omppclb>"

set result [regexp {omppclb>\s*(.+)\s*omppclb>} $output match str_extr];

puts "String to apply the pattern:\n'$output'"
puts "result=$result"
if {$result} {
  puts "This was matched:\n'$match'"
  puts "String extracted:\n'$str_extr'"
}

puts "\n\n"

# matching multi line string
set output "omppclb> error: fialed due to mismatch of values
                       Existed value : 20000
                        expected value: 40000
                        omppclb>"

set result \
  [regexp -lineanchor {omppclb>\s*(.+)\s*omppclb>} $output match str_extr];

puts "String to apply the pattern:\n'$output'"
puts "result=$result"
if {$result} {
  puts "This was matched:\n'$match'"
  puts "String extracted:\n'$str_extr'"
}
Output:

CODE

String to apply the pattern:
'omppclb> error: fialed due to mismatch of values Existed value : 20000 expected
 value: 40000 omppclb>'
result=1
This was matched:
'omppclb> error: fialed due to mismatch of values Existed value : 20000 expected
 value: 40000 omppclb>'
String extracted:
'error: fialed due to mismatch of values Existed value : 20000 expected value: 4
0000 '



String to apply the pattern:
'omppclb> error: fialed due to mismatch of values
                       Existed value : 20000
                        expected value: 40000
                        omppclb>'
result=1
This was matched:
'omppclb> error: fialed due to mismatch of values
                       Existed value : 20000
                        expected value: 40000
                        omppclb>'
String extracted:
'error: fialed due to mismatch of values
                       Existed value : 20000
                        expected value: 40000
                        '

RE: i want to grep expected output between two string in patter?

(OP)
t hanks its working but sometimes omppch root> will come instead of omppclb> so can u modify . i tried to modify and run but failed:

set output "omppclh root > error: mismatch in cells
                                                 expected cell:40000
                                                  existed cell  :50000
                       omppclh root>

some times server may display omppclv4 root> instead of omppclh> can you plz help me.

SHRIKANT BADIGER
SJCE MYSORE

RE: i want to grep expected output between two string in patter?

then change the reelvant part of code to

CODE

set result \
  [regexp -lineanchor {omppclb\s*[root]*>\s*(.+)\s*omppclb>} $output match str_extr];

RE: i want to grep expected output between two string in patter?

I overlooked the characters omppclh and omppclv4. Maybe this does what you need:

CODE

proc extract_string {str} {                       
  set result \
  [regexp -lineanchor \
    {omppcl(b|h|v4)\s*[root]*\s*>\s*(.+)\s*omppcl(b|h|v4)\s*[root]*\s*>} \
    $str match tmp str_extr];

  if {$result} {
      return $str_extr
  }
}

#------------------------------------------------------------------------
# matching single line string
puts "Matching single line string:\n"

set my_string "omppclb> error: fialed due to mismatch of values Existed value : 20000 expected value: 40000 omppclb>"

puts "String to apply the pattern:\n'$my_string'"
set my_substring [extract_string $my_string]
puts "Substring extracted:\n'$my_substring'"

puts "\n\n"

#------------------------------------------------------------------------
# matching multi line strings
puts "Matching multi line strings:\n"

set my_string "omppclb > error: fialed due to mismatch of values
                       Existed value : 20000
                        expected value: 40000
                        omppclb>"
puts "String to apply the pattern:\n'$my_string'"
set my_substring [extract_string $my_string]
puts "Substring extracted:\n'$my_substring'"

puts "\n"

set my_string "omppclh root > error: fialed due to mismatch of values
                       Existed value : 20000
                        expected value: 40000
                        omppclh root>"
puts "String to apply the pattern:\n'$my_string'"
set my_substring [extract_string $my_string]
puts "Substring extracted:\n'$my_substring'"

puts "\n"

set my_string "omppclv4 root> error: fialed due to mismatch of values
                       Existed value : 20000
                        expected value: 40000
                        omppclv4 root >"
puts "String to apply the pattern:\n'$my_string'"
set my_substring [extract_string $my_string]
puts "Substring extracted:\n'$my_substring'"
Output:

CODE

Matching single line string:

String to apply the pattern:
'omppclb> error: fialed due to mismatch of values Existed value : 20000 expected
 value: 40000 omppclb>'
Substring extracted:
'error: fialed due to mismatch of values Existed value : 20000 expected value: 4
0000 '



Matching multi line strings:

String to apply the pattern:
'omppclb > error: fialed due to mismatch of values
                       Existed value : 20000
                        expected value: 40000
                        omppclb>'
Substring extracted:
'error: fialed due to mismatch of values
                       Existed value : 20000
                        expected value: 40000
                        '


String to apply the pattern:
'omppclh root > error: fialed due to mismatch of values
                       Existed value : 20000
                        expected value: 40000
                        omppclh root>'
Substring extracted:
'error: fialed due to mismatch of values
                       Existed value : 20000
                        expected value: 40000
                        '


String to apply the pattern:
'omppclv4 root> error: fialed due to mismatch of values
                       Existed value : 20000
                        expected value: 40000
                        omppclv4 root >'
Substring extracted:
'error: fialed due to mismatch of values
                       Existed value : 20000
                        expected value: 40000

RE: i want to grep expected output between two string in patter?

(OP)
thanks.. again our requirement changed..
now the ouput is in following format:

"omppclh> perl pcmd_verify.pl 2000 20000 2000 4567 343455 545
ERROR: cell mismatch:
expected cell: 10000
existed cell : 20000
omppclh>

now i want grep the output from ERROR
i don't want perl pcmd_verify.pl 2000 20000 2000 4567 343455 545
only i want to fetch
ERROR: cell mismatch:
expected cell: 10000
existed cell : 20000



plz help me
 

SHRIKANT BADIGER
SJCE MYSORE

RE: i want to grep expected output between two string in patter?

try self to change the regular expression

RE: i want to grep expected output between two string in patter?

(OP)
ok.. thanks,,
i changed..its running properly..
 

SHRIKANT BADIGER
SJCE MYSORE

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close