- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Extracting data in between strings...using perl
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-03-2008 11:20 AM
тАО01-03-2008 11:20 AM
When i print the content it gives me this:
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.
I want to print everthing between START and END and then reassign it to my WebJump variable.
Any ideas?
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-03-2008 11:41 AM
тАО01-03-2008 11:41 AM
Re: Extracting data in between strings...using perl
Use sed.
WebJump=`echo "the_stuff"|sed /^BEGIN/,/^END/p`
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-03-2008 11:44 AM
тАО01-03-2008 11:44 AM
Re: Extracting data in between strings...using perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-03-2008 11:45 AM
тАО01-03-2008 11:45 AM
Re: Extracting data in between strings...using perl
Will let you know if I find something. SOrry for the quick wrong answer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-03-2008 11:47 AM
тАО01-03-2008 11:47 AM
Re: Extracting data in between strings...using perl
IE
...whatever.....
I simply used search and replace....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-03-2008 11:53 AM
тАО01-03-2008 11:53 AM
Re: Extracting data in between strings...using perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-03-2008 11:54 AM
тАО01-03-2008 11:54 AM
Re: Extracting data in between strings...using perl
If whole text is single line (otherwise please parse into single line)
use index function to find START
use substr function to extract from START to end of the line (str1)
Then you have 2 END in text,
so if you want to extract START and first END
again use index function with str1 to find first END's position. and use substr
if you want to extract BEGIN and second END
use rindex with str1 to find position of second END, then subtract it from len($str1)
use again substr
I have no perl interpreter on this computer so I hope this algorithm will help to you
Best Regards
Murat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-03-2008 01:50 PM
тАО01-03-2008 01:50 PM
Re: Extracting data in between strings...using perl
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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-03-2008 02:30 PM
тАО01-03-2008 02:30 PM
SolutionActually, here is a better representation of what you probably want. It destructively updates the $WebJump scalar variable:
# cat .jody.pl
#!/usr/bin/perl
use strict;
use warnings;
my $WebJump=q[
ta while you are being authorized for your reque st.
You will be forwarded to continue the authorization process. If th
is does not happen automatically, please click the Continue button below.];
( $WebJump ) = ( $WebJump =~ /START(.*)END/s );
print "$WebJump\n";
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-03-2008 05:06 PM
тАО01-03-2008 05:06 PM
Re: Extracting data in between strings...using perl
Jody,
Murat pointed out that there are two ENDs in the example. I believe you indicate that was just a bad example, thus nothing to worry about. (allthough it worries me when folks post bad examples, but that's my problem).
Still, if you did have to deal with nested START/ENDs then you may want to be sure to know about the 'greedyness' of the * in perl.
For example if the data was:
x START y START a b d END z END
JRF writes...
( $WebJump ) = ( $WebJump =~ /START(.*)END/s );
This is fine. But note that the .* in there is greedy and in my example will return " y START a b d END z "
If you wanted the inner START/END, then use: .*?
It will return " a b d "
Cheers!
Hein.