tags:

views:

99

answers:

2

I am looking to replace a nasty shell script that uses awk to trim down some HTML. The problem is I cannot find anything in Perl that does the aforementioned function

awk '/<TABLE\ WIDTH\=\"100\%\" BORDER\=1\ CELLSPACING\=0><TR\ class\=\"tabhead\"><TH>State<\/TH>/,/END/'

How can I do this in Perl?

the expected output would be

<TABLE WIDTH="100%" BORDER=1 CELLSPACING=0><TR class="tabhead"><TH>State</TH>

The Perl flipflop operator gives me WAY more. (Everything between the asterisks is junk)

*<h2>Browse Monitors (1 out of 497)</h2><br><font size="-1" style="font-weight:normal"> Use the <A HREF=/SiteScope/cgi/go.exe/SiteScope?page=monitorSummary&account=login15 >Monitor Description Report</a> to view current monitor configuration settings.</font>*<TABLE WIDTH="100%" BORDER=1 CELLSPACING=0><TR class="tabhead"><TH>State</TH>
A: 

As a one-liner (slightly changed since first post):

perl -n -e '$started = 1 if /<TABLE\ WIDTH\=\"100\%\" BORDER\=1\ CELLSPACING\=0><TR\ class\=\"tabhead\"><TH>State<\/TH>/; next unless $started; print; last if /END/;'

From the perlrun man page:

   -n   causes Perl to assume the following loop around your program,

which makes it iterate over filename arguments somewhat like sed -n or awk:

          LINE:
            while (<>) {
                ...             # your program goes here
            }

And then the core of the body is to wait for the start, then print every line until the end.

hlovdal
+4  A: 
mobrule
it is called "flip-flop" operator.
J.F. Sebastian
Awesome! thanks for the assistance!
kSiR
appears the flipflop doest trim the way I figured it would. I need to trim all the data infront of it, it appears the flip-flop only looks to see the line "contains" it where the awk actually cuts it down to just the looked for text.
kSiR
Again mobrule you came through with the win... now I need to sit down and figure out what you did ;)
kSiR