extract data from notepad - perl

can u give me a script for the following?

1.txt
___________________________________________
XXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXBBBBBBBBBBB
WWWWWOOOOONNNNNNNNNNNN
WwwIIIIIOOOOOOO |quote= "pravin"| SSSSSSSSSSSS
SSSSSSSSSSSSSSSSSSSSSS
SSSSSSSSSSSS
SSSSSSSSSSSSSSSSSSSS
SSSSSSSSSSS |/quote| UUUWWWDDDDDDD
XXXWWXXXXXXBBBBXXXBBBBBBB
WWWWWOOSSSSSSSSS
SSSSSSSSS
___________________________________________

Required OUTPUT:

SSSSSSSSSSSS
SSSSSSSSSSSSSSSSSSSSSS
SSSSSSSSSSSS
SSSSSSSSSSSSSSSSSSSS
SSSSSSSSSSS
pravink22Asked:
Who is Participating?
 
tel2Commented:
Hi pravink22,

Here's one way of rewriting ozo's on-liner as a full script:

    #!/usr/bin/perl
    undef $/;
    $_ = <>;
    ($_) = /\|quote= "pravin"\|\s*(.*?)\s*\|\/quote\|/s;
    print "$_\n";

However, there are some practical differences between this and ozo's, i.e.:
1. The above removes any spaces from the beginning and end of the output.  If you don't want to do that, remove the 2 instances of "\s*".
2. This above puts a newline character at the end of the output.  If you don't want this, change the last line to:
    print $_;
or just:
    print;
since $_ is the default print argument.

If you're going to have other code in the same script after the above code, then it would be safer to do something like this:

    #!/usr/bin/perl
    {
        local $/ = undef;
        $_ = <>;
        ($_) = /\|quote= "pravin"\|\s*(.*?)\s*\|\/quote\|/s;
        print "$_\n";
    }
    # Other code here...

otherwise your input separator ($/) will still be undefined afterwards, which may cause problems in any subsequent code.

If you do accept this answer, remember to give ozo some points, since this is based on his one-liner.

tel2
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
Do your require that perl is used? I'd use a simple grep to get your output:

grep -o [S]* 1.txt

Open in new window


Output:

SSSSSSSSSSSS
SSSSSSSSSSSSSSSSSSSSSS
SSSSSSSSSSSS
SSSSSSSSSSSSSSSSSSSS
SSSSSSSSSSS
SSSSSSSSS
SSSSSSSSS

Open in new window

0
 
pravink22Author Commented:
Hi,

My requirement is to grep data present in between

|quote= "pravin"| to  |/quote|

Thanks
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ozoCommented:
perl  -0777 -pe '($_)=/\|quote= "pravin"\|(.*?)\|\/quote\|/s'  1.txt
0
 
pravink22Author Commented:
can you write the full program?
0
 
tel2Commented:
Thanks for the points, pravink.

Probably some of the points should have gone to others (especially ozo, who needs them so badly), so bear that in mind for the future.  As I had indicated, my scripts were based on ozo's one-liner.  I assume you know how to split points among multiple experts?

tel2
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.