The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Concatenating the two lines in a file srivsn Shell Programming and Scripting 6 07-17-2008 10:03 PM
Concatenating multiple lines to one line if match pattern phixsius Shell Programming and Scripting 13 01-24-2008 11:02 PM
concatenating strings.. jt_csv Shell Programming and Scripting 2 02-07-2007 10:09 PM
Formatting lines in shell script dreams5617 Shell Programming and Scripting 8 01-30-2007 01:24 AM
Formatting the lines dreams5617 UNIX for Dummies Questions & Answers 2 01-29-2007 06:46 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-30-2004
Tonka52 Tonka52 is offline
Registered User
  
 

Join Date: Feb 2004
Posts: 14
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

</th>
</tr>
<tr>
<td>
<ul>

<li><a href="test.txt">Email</a></li>

<li><a href="test2.htm=">See details</a></li>

</td>
<td>
Darren Brown<br />



077087313<br />


Yes<br />

</td>
</tr>
</table>

I need it to end up like:

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

and so on.....
  #2 (permalink)  
Old 11-30-2004
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
A job for perl, IMHO....
Code:
#!/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
  #3 (permalink)  
Old 11-30-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Awk one liner...

awk '/<table/,/<\/table/{printf $0 ($0~"</table"?"\n":"");next}{print}' file1 > file2
  #4 (permalink)  
Old 12-01-2004
Tonka52 Tonka52 is offline
Registered User
  
 

Join Date: Feb 2004
Posts: 14
Thanks guys! Worked a charm.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0