Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

Extracting data in between strings...

 
SOLVED
Go to solution
Highlighted
Super Advisor

Extracting data in between strings...

I have a variable called WebJump in a perl script.

When i print the content it gives me this:


T
his page is used to hold your data while you are being authorized for your reque
st.

You will be forwarded to continue the authorization process. If this
does not happen automatically, please click the Continue button below.
="AUTOSUBMIT" METHOD="POST" STARThttps://test.ip.com/siteminderagent/forms/
login.fcc?TYPE=33554433&REALMOID=06-00034bb7-e037-116f-8241-808d67a50008&GUID=&S
MAUTHREASON=0&METHOD=POST&SMAGENTNAME=$SM$8OJVwItP%2fV8GXRhL%2fhch6KJt3EvC2AWLQ7
%2bWLfTgx3%2bWD7k%2buJc3dVSFPOr1jTxg&TARGET=$SM$%2fEND="HIDDEN" NAME="SMPostPres
erve" VALUE="S1NJbjNmby81VzRqMmo0cTNuWm9NdFo3cVpZSlF6enpMc2laNWZrcnRudlhWVEUzM0x
UTHVPR1Y3REpwNnUwM1ZVd1IySFdQZkRDRmpUQldrV01ybk9pcEFBZnpzNmg4RG1yQ0lRQUNzbTFMekd
iUG9Eck02M2NUcis4RG5YQ3l2dkZHOGp4WDRPbHJJTFdJOXUvbnFBPT0END="SUBMIT" VALUE="Cont
inue">


I want to print everthing between START and END and then reassign it to my WebJump variable.

Any ideas?
4 REPLIES 4
Highlighted
Honored Contributor

Re: Extracting data in between strings...

This might point you in the right direction:
http://www.wellho.net/forum/Perl-Programming/return-part-of-a-string-that-matches-a-pattern.html

like this:
$WebJump =~ /START(.*)END/;
print "We got $1 out of that!\n";
jaton
Highlighted
Acclaimed Contributor

Re: Extracting data in between strings...

Hi Jody:

I assume from the content that you truly want everything between the strings START and END, disregarding any newline boundries.

Using a copy-and-paste of your data :

# echo ${WebJump}|perl -000 -nle 'print $1 if m/.*START(.*)END.*/s'

Regards!

...JRF...
Highlighted
Trusted Contributor
Solution

Re: Extracting data in between strings...

Hi,

Where-ever the variable 'WebJump' has this value, use the following lines in your perl script:

if($WebJump =~ /START(.*)END/s) {
print "Stuff between 'START' and 'END': $1\n"
}

- Suraj
What we cannot speak about we must pass over in silence.
Highlighted
Super Advisor

Re: Extracting data in between strings...

I needed to add a cookie container.

# Open Cookie Object
my $cookie_jar = HTTP::Cookies->new(
file => "/adminweb/usm/tlrs/cookies.t",
autosave => 1,
);