Concatenating lines and formatting.

Hi,

I have a html file which is unformatted and need to concatenate the lines between each "table" statement in order to run an awk statement on it. Here is the example of the raw file:

                    <table border="0" cellspacing="0" cellpadding="0" class="playerDetails">

def
<tr>
<th colspan="3">
Michael Anthony

                                    &lt;/th&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                    &lt;td&gt;
                                            &lt;ul&gt;

                                                    &lt;li&gt;&lt;a href="test.txt"&gt;Email&lt;/a&gt;&lt;/li&gt;

                                                    &lt;li&gt;&lt;a href="test2.htm="&gt;See details&lt;/a&gt;&lt;/li&gt;

                                    &lt;/td&gt;
                                    &lt;td&gt;
                                            Darren Brown&lt;br /&gt;



                                                    077087313&lt;br /&gt;


                                                    Yes&lt;br /&gt;

                                    &lt;/td&gt;
                            &lt;/tr&gt;
                    &lt;/table&gt;

I need it to end up like:

<table> .....[all other info].....</table>
<table>...[next load of info]......</table>

and so on.....

A job for perl, IMHO....

#!/usr/bin/perl

open( HANDLE, "< ./somefile" );
@file=<HANDLE>;
close(HANDLE);

$flag=0;

foreach (@file)
{
  if ( $_ =~ "<table" ) {
     $flag=1;
  }
  elsif ( $_ =~ "</table>" ) {
     print( "$_" );
     $flag=0;
  }
  if ( $flag == 1 ) {
     $_ =~ s/\n//g;
     print( "$_" );
  }
}

Cheers
ZB

Awk one liner...

awk '/<table/,/<\/table/{printf $0 ($0~"</table"?"\n":"");next}{print}' file1 > file2

Thanks guys! Worked a charm.