Solved

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

Posted on 2000-05-10
8
216 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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 gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now