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
How do I extract text only from html file without HTML tag los111 UNIX for Dummies Questions & Answers 4 11-28-2007 04:40 AM
HTML message with attachment (text-file) Felix2511 UNIX for Dummies Questions & Answers 2 09-12-2007 03:59 AM
html - text file question frustrated1 Shell Programming and Scripting 5 09-21-2005 06:23 AM
Converting Text File into XML using Unix Shell Scripts Laud12345 Shell Programming and Scripting 10 02-16-2005 01:35 PM
linking unix generated text file to html page alexd Shell Programming and Scripting 1 11-13-2002 12:21 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 10-29-2008
ph0enix ph0enix is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 26
Converting a text file to HTML

Hi,
I need to convert a text file formatted like this ("tshark -z conv,ip" output) to HTML:

Code:
=====================================================================================================
IPv4 Conversations
Filter:<No Filter>
                                               |       <-      | |       ->      | |     Total     |
                                               | Frames  Bytes | | Frames  Bytes | | Frames  Bytes |
192.168.1.246      <-> 192.168.1.135            2       276       1        60       3       336
192.168.1.255      <-> 192.168.1.167            2       184       0         0       2       184
192.168.1.255      <-> 192.168.1.99             1       265       0         0       1       265
192.168.1.255      <-> 192.168.1.164            1       126       0         0       1       126
10.0.0.255      <-> 10.0.0.250            1       126       0         0       1       126
192.168.1.255      <-> 192.168.1.41             1        92       0         0       1        92
=====================================================================================================
Preferably the rows and the columns would be in a table so the data is nicely aligned. Are there any tools that would allow me to do this from a script? ...or do I need to use sed/awk? If so, how?

Thank you!
  #2 (permalink)  
Old 10-29-2008
ph0enix ph0enix is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 26
Let me be more specific. I can display the data I need by doing:

Code:
awk '//{print $1,$3,$5,$7,$9}' file.txt |grep -v "|" |grep -v "Filter" |grep -v "IPv4" |grep -v "="
Now I would like to add the following HTML tags:

<TR><TD> in front of $1
</TD><TD> in front of $2, $3, $5, $7, $9
</TD></TR> at the end of each line (after $9)

How would I go about doing that?

Thank you!
  #3 (permalink)  
Old 10-29-2008
ph0enix ph0enix is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 26
Here's what I did and it actually works. It's very inefficient though:

Code:
awk '//{print $1,$3,$5,$7,$9}' file.txt |grep -v "|" |grep -v "Filter" |grep -v "=" |grep -v "IPv4" |sed 's/^/<TR><TD>/' |sed 's" "</TD><TD>"' |sed 's" "</TD><TD>"' |sed 's" "</TD><TD>"'|sed 's" "</TD><TD>"' |sed 's"$"</TD></TR>"g' >file.htm
Can you guys help me shorten it?

Grazie!
  #4 (permalink)  
Old 10-29-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,428
This should work:
Code:
awk -v a="<TR><TD" -v b="</TD><TD>" -v c="</TD></TR>" 'BEGIN{print "<html><table>"}/^[0-9]/{print  a$1b$3b$5b$7b$9c}END{print "</table></html>"}' file.txt > file.htm

Last edited by danmero; 10-29-2008 at 06:23 PM..
  #5 (permalink)  
Old 10-29-2008
ph0enix ph0enix is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 26
Sweet!
Thank you!
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 03:33 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