Hi
I need to convert some columns form a html file to rows.
I do manage to make it works without help (some proud
)
For some reason the offline status is not in bold, so I do need to remove the <b> tag from the other field to make this to work. All fields are not needed, so I test and select only one that I need.
Is there a more simple way to do this or can this code be cleaned some?
infile
ohter blablabla
<TH TITLE="Different services during last 60s">CASC USERS</TH>
<TH colspan="3" class="centered">Action</TH>
</TR>
<TR class="online">
<TD class="usercol1"><SPAN TITLE="">master</SPAN></TD>
<TD class="usercol2"><b>online</b></TD>
<TD class="usercol3">148.31.202.211</TD>
<TD class="usercol4">40</TD>
<TD class="usercol5">4380</TD>
<TD class="usercol6">55</TD>
</TR>
<TR class="offline">
<TD class="usercol1"><SPAN TITLE="">madrid</SPAN></TD>
<TD class="usercol2">offline</TD>
<TD class="usercol3"></TD>
<TD class="usercol4">0</TD>
<TD class="usercol5">120</TD>
<TD class="usercol6">0</TD>
</TR>
<TR class="connected">
<TD class="usercol1"><SPAN TITLE="">london</SPAN></TD>
<TD class="usercol2"><b>connected</b></TD>
<TD class="usercol3">10.10.10.41</TD>
<TD class="usercol4">34</TD>
<TD class="usercol5">632</TD>
<TD class="usercol6">430</TD>
</TR>
</TABLE><BR>
more .....
script
sed 's/<b>//g' infile | awk -F"[<>]" '{if ($0~"TR class=") {a=1}};
{if ($0~"/TR" && a==1) {a=0; print ""}};
{if ($0~"col1\"") printf "%s",$5};
{if ($0~"col2\"") printf "%s%s",",",$3};
{if ($0~"col3\"") printf "%s%s",",",$3};
{if ($0~"col5\"") printf "%s%s",",",$3}'
output
master,online,148.31.202.211,4380
madrid,offline,,120
london,connected,10.10.10.41,632