Solved

Parsing to get a part of a string from a string!

Posted on 2000-05-10
8
233 Views
Last Modified: 2010-03-05
for example assuming the result this line of code
$label_and_OID = `idlcall $NROID get_all '"RemoteControl" $SIZE'`;
is:
=====================================================
{1 { 1234567889.1.1028PcRC::RemoteControl# "test" { { null }}}}OBJECT_NIL
=====================================================

Now I need to parse the result of the IDLCALL inoreder to
get the below info stored into the respective variables

$HUB_REGION_NUMBER=1234567889
$RC_OBJECT_ID=1234567889.1.1028

Thanks.  I need this Regular Expression/pattern matching like ASAP.
I would appreciate your HELP!!

CODER.
0
Comment
Question by:CODER
  • 5
  • 2
8 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2797577
here is the solution using reg exps...

#!/usr/local/bin/perl

$label_and_OID='{1 { 1234567889.1.1028PcRC::RemoteControl# "test" { { null }}}}
OBJECT_NIL ';

$label_and_OID=~ /{\d+\s+{\s+((\d+)\.\d+\.\d+)[A-Za-z]+/;

$HUB_REGION_NUMBER=$2;
$RC_OBJECT_ID=$1;

print $HUB_REGION_NUMBER,"\n";
print $RC_OBJECT_ID,"\n";
0
 

Author Comment

by:CODER
ID: 2797597
{1 { 1234567889.1.1028PcRC::RemoteControl# "test" { { null }}}}OBJECT_NIL

the string that says "test" will have an actual string that looks like so:

PPP code.servername.iga.app.bbrc-object

and I will want to also extract part of this string from the part that reads

 iga.app.bbrc-object

and store it in a variable called
$RC_LABEL

thanks....
0
 

Author Comment

by:CODER
ID: 2797624
for example assuming the result this line of code
$label_and_OID = `idlcall $NROID get_all '"RemoteControl" $SIZE'`;
is:
=====================================================
{1 { 1234567889.1.1028PcRC::RemoteControl# "test" { { null }}}}OBJECT_NIL
=====================================================
the string that says "test" will have an actual string that looks like so:

PPP code.servername.iga.app.bbrc-object
and I will want to also extract part of this string from the part that reads

iga.app.bbrc-object
Now I need to parse the result of the IDLCALL inoreder to
get the below info stored into the respective variables

$HUB_REGION_NUMBER=1234567889
$RC_OBJECT_ID=1234567889.1.1028
$RC_LABEL = iga.app.bbrc-object

Thanks.  I need this Regular Expression/pattern matching like ASAP.
I would appreciate your HELP!!

                      CODER.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 12

Accepted Solution

by:
geotiger earned 50 total points
ID: 2797803
Here is the code:


#!/usr/local/bin/perl

$test = "PPP code.servername.iga.app.bbrc-object";

$str = "{1 { 1234567889.1.1028PcRC::RemoteControl# $test { { null }}}}OBJECT_NIL";

# $HUB_REGION_NUMBER=1234567889
# $RC_OBJECT_ID=1234567889.1.1028
# $RC_LABEL = iga.app.bbrc-object

print "$str\n";
if ($str =~ /{1 {\s*(\d+)([\d.]+)\w*::\w*#\s*PPP\s*\w*\.\w*\.([\w.]+)/) {
    print "1: $1: $2 : $3\n";
    $HUB_REGION_NUMBER=$1;
    $RC_OBJECT_ID="$1$2";
    $RC_LABEL=$3;
}
print "\$HUB_REGION_NUMBER=$HUB_REGION_NUMBER\n";
print "\$RC_OBJECT_ID=$RC_OBJECT_ID\n";
print "\$RC_LABEL=$RC_LABEL\n";



The output is :

{1 { 1234567889.1.1028PcRC::RemoteControl# PPP code.servername.iga.app.bbrc-object { { null }}}}OBJECT_NIL
1: 1234567889: .1.1028 : iga.app.bbrc
$HUB_REGION_NUMBER=1234567889
$RC_OBJECT_ID=1234567889.1.1028
$RC_LABEL=iga.app.bbrc
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2797880
CODER,

you have to be clear about while describing the problem. nowhere in your original Q did you clarify about test being a variable.

now you have decided to change the Q. in such cases its very difficult to provide a properly working code/code snippet.
0
 

Author Comment

by:CODER
ID: 2798012
maneshr :I AM SORRY ABT THAT... I WILL NOT MAKE THAT ERROR AGAIN.  MY BADD!!!!!
0
 

Author Comment

by:CODER
ID: 2798026
HEY
I am curious as to how
if ($str =~ /{1 {\s*(\d+)([\d.]+)\w*::\w*#\s*PPP\s*\w*\.\w*\.([\w.]+)/)

gets the iga.app.bbrc  string that I want... what part of that regular expression does this?  I see where it strips the PPP away... where does it strip the
=============
code.servername.
=============
is it the \s*\w*\.\w*\.  ???

PPP code.servername.iga.app.bbrc-object"

thanks
0
 

Author Comment

by:CODER
ID: 2798077
geotiger's comment
====================================================
#!/usr/local/bin/perl

 $test = "PPP code.servername.iga.app.bbrc-object";

$str = "{1 { 1234567889.1.1028PcRC::RemoteControl# $test { { null }}}}OBJECT_NIL";

                      # $HUB_REGION_NUMBER=1234567889
                      # $RC_OBJECT_ID=1234567889.1.1028
                      # $RC_LABEL = iga.app.bbrc-object

 print "$str\n";
 if ($str =~ /{1 {\s*(\d+)([\d.]+)\w*::\w*#\s*PPP\s*\w*\.\w*\.([\w.]+)/) {
                          print "1: $1: $2 : $3\n";
                          $HUB_REGION_NUMBER=$1;
                          $RC_OBJECT_ID="$1$2";
                          $RC_LABEL=$3;
                      }
                      print "\$HUB_REGION_NUMBER=$HUB_REGION_NUMBER\n";
                      print "\$RC_OBJECT_ID=$RC_OBJECT_ID\n";
                      print "\$RC_LABEL=$RC_LABEL\n";



                      The output is :

                      {1 { 1234567889.1.1028PcRC::RemoteControl# PPP code.servername.iga.app.bbrc-object { { null }}}}OBJECT_NIL
                      1: 1234567889: .1.1028 : iga.app.bbrc
                      $HUB_REGION_NUMBER=1234567889
                      $RC_OBJECT_ID=1234567889.1.1028
                      $RC_LABEL=iga.app.bbrc
====================================================
NOW SUPPOSING for my $RC_LABEL variable, I want the
complete info which is:
PPP code.servername.iga.app.bbrc-object

how would I do this??????
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question