Shell command output into HTML


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell command output into HTML
# 1  
Old 12-31-2012
Linux Shell command output into HTML

Hi unix geeks out there,
I have a file that contains the output of a command in text format
Code:
------------------------------------------------------------------------ r201535 | kashyapgiri@gmail.com| 2012-06-21 05:00:01 +0530 (Thu, 21 Jun 2012) |  1 line Changed paths: M /client/j2me/cc/cool/v.0/j2me/src/main/java/com/airone/cclient/j2me/db/RL.java Bug 63493 - J2ME : Pending Contact Count issue after SAS in Samsung 5230, Samsung b3410  URL:cor.airone/vv/AirOne/client/j2me/cc/cool/v.0/j2me/src/main/java/com/airone/cclient/j2me/db/RL.java ------------------------------------------------------------------------ r201572 | kashyapmanju@gmail.com | 2012-06-21 22:27:37 +0530 (Thu, 21 Jun 2012) |  1 line Changed paths: M /client/j2me/cc/cool/v.0/j2me/src/main/java/com/airone/cclient/j2me/db/resources.xml Error message has changed for invalid pin.  URL:cor.airone/vv/AirOne/client/j2me/cc/cool/v.0/j2me/src/main/java/com/airone/cclient/j2me/db/resources.xml  ------------------------------------------------------------------------ r201575 | ngupta@gmail.com | 2012-06-21 22:45:06 +0530 (Thu, 21 Jun 2012) |  1 line Changed paths: M /client/j2me/cc/cool/v.0/j2me/src/main/java/com/airone/cclient/j2me/db/MB.java Samsung Wave S8500 UI changes  URL:cor.airone/vv/AirOne/client/j2me/cc/cool/v.0/j2me/src/main/java/com/airone/cclient/j2me/db/MB.java

,

The giant task that lies in front of me is I need to edit each line of the file and format it into HTML output in order to send a mail.
The major problem is the highlighted part should be represented as a link with the name THE LINK ,on clicking the link i should be able to go to the actual page.
The output i need is as below,

Code:
------------------------------------------------------------------------  r201535 | kashyapgiri@gmail.com| 2012-06-21 05:00:01 +0530 (Thu, 21 Jun  2012) |  1 line Changed paths: M  /client/j2me/cc/cool/v.0/j2me/src/main/java/com/airone/cclient/j2me/db/RL.java  Bug 63493 - J2ME : Pending Contact Count issue after SAS in Samsung  5230, Samsung b3410  THE LINK------------------------------------------------------------------------  r201572 | kashyapmanju@gmail.com | 2012-06-21 22:27:37 +0530 (Thu, 21  Jun 2012) |  1 line Changed paths: M  /client/j2me/cc/cool/v.0/j2me/src/main/java/com/airone/cclient/j2me/db/resources.xml  Error message has changed for invalid pin.  THE LINK  ------------------------------------------------------------------------  r201575 | ngupta@gmail.com | 2012-06-21 22:45:06 +0530 (Thu, 21 Jun  2012) |  1 line Changed paths: M  /client/j2me/cc/cool/v.0/j2me/src/main/java/com/airone/cclient/j2me/db/MB.java  Samsung Wave S8500 UI changes  THE LINK  ------------------------------------------------------------------------

The thing is even though "THE LINK" part is displayed same, it should take me to different pages based on the selection.
Also i am allowed to place the remaining part of the file in a table or so.
I hope i have explained my problem well.
Please help me out in achieving this task.

Thanks,
Kashyap.
# 2  
Old 12-31-2012
A link in HTML looks like the following:

Code:
<a href=[target URL here]>[link text here]</a>

The following sed-command should get you what you want:

Code:
sed 's/\(URL:[^ ]*\)/<a href=\1>THE LINK<\/a>/g' /path/to/infile > outfile

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 3  
Old 12-31-2012
Do you want a piece of code to accomplish this ?
# 4  
Old 12-31-2012
Hi SathyaOnunix,
Yep i do need a piece of code as a solution.
Please do help me.
Thanks,
Kashyap.

---------- Post updated at 02:19 PM ---------- Previous update was at 02:18 PM ----------

HI Bakunin,

I hav tried the the result u have given me.
Its not the solution i need.
Thanks,
Kashyap.
# 5  
Old 12-31-2012
You can try this, but they may be more easier way than mine Smilie

Code:
sed 's/--*[$-]/\n/g' file  | awk -F'|' 'BEGIN{print "<html>\n<table border="3" cellspacing="1" cellpadding="2">"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";p
rint "</tr>"} END{print "</table>\n</html>"}' | sed 's/\(URL:[^ ]*\)/<a href=\1>THE LINK<\/a>/g'

This User Gave Thanks to sathyaonnuix For This Post:
# 6  
Old 12-31-2012
Quote:
Originally Posted by Kashyap
I hav tried the the result u have given me.
Its not the solution i need.
Then show the input you fed the script, the output it produced and in which way this differs from the desired result. I can write scripts, but not read minds.

bakunin
# 7  
Old 12-31-2012
Hi bakunin,
I didn't mean to say your script wont work , it is part of my task.
As sathyaonunix suggested i needed the code to fulfill my task.
Hope i am clear. And please don consider my reply as a disrespect.
Your code works fine and creates the links as required.
Thanks,
Kashyap.

---------- Post updated at 04:28 PM ---------- Previous update was at 04:22 PM ----------

Hi sathya,

Your piece of code works marvellous.
But there is a slight hindrance i my task.
Will try to explain to you.
After i obtain the html tags as output i need to send a mail in the html format,
Hope u understand my problem.
I am using the below code to send the mail.
Code:
echo "Sending mail....."
cat -  <<EOF | sendmail -oi -t
From: ${MAILFROM}
To: ${MAILTO}
Subject: Mail script
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
EOF
echo "Done!!!"

The Now please tell me how i can encapsulate the html output that you provided me into the mail.
I hope you understood my problem.
In simple words the output of the html should be encapsulated in the mail.
Thanks,
Kashyap.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Arranging the command output into an html table format

Hi, I need to format a command output for the beolow command: runmqckm -cert -list -db $MQ_KDB -pw $PASSWD -expiry $EXP | grep -v "Certificates in database" The output will be: "ABC - cert name" From: Tuesday, May 25, 1999 11:09:40 AM CDT To: Saturday, May 25, 2019 11:39:40 AM CDT ... (3 Replies)
Discussion started by: bdpl
3 Replies

2. Shell Programming and Scripting

Convert shell script output txt file to html table

My concnern related to the post -Convert shell script output txt file to html table, in this how to print the heading as color. awk 'BEGIN{print "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}' <filename> (8 Replies)
Discussion started by: sarajobmai
8 Replies

3. Shell Programming and Scripting

[Solved] Shell script output in HTML or with table like results and mail

Hello, Currently i have a script which will disply the results in plain text format. I want to format the result in more readable format like Making bold headings and format with colors etc. Something like html and send that content as email. Please help me how i can do that. I am using... (10 Replies)
Discussion started by: joy lobo
10 Replies

4. Web Development

Get command-output to webpage from solaris-10-OS invoked from html webpages

Hello, I am a middleware administrator and as an admin I need to monitor a number of middleware instances (weblogic servers). But since it is a not the forum for that i would like to put my problem in simple terms and need guidance on that. I need to use apache webserver on Solaris 10 zones to... (3 Replies)
Discussion started by: poga
3 Replies

5. Shell Programming and Scripting

Convert shell script output txt file to html table

Hi, I have script which generates the output as below: Jobname Date Time Status abc 12/9/11 17:00 Completed xyz 13/9/11 21:00 Running I have the output as a text file. I need to convert it into a HTML Table and sent it thru email ... (6 Replies)
Discussion started by: a12ka4
6 Replies

6. Shell Programming and Scripting

shell script output in HTML or with table like results

Hello, Currently i have a ksh script which will disply the results in plain text format. I want to format the result in more readable format like Making bold headings and format with colors etc. Something like html or excel format and send that content as email. Please help me how i can do... (2 Replies)
Discussion started by: kotasateesh
2 Replies

7. Red Hat

Send HTML body and HTML attachment using MUTT command

Hi there.. I need a proper "mutt" command to send a mail with html body and html attachment at a time. Also if possible let me know the other commands to do this task. Please help me.. (2 Replies)
Discussion started by: vickramshetty
2 Replies

8. Programming

How to read output of a shell command

Hello All, I have a an application written in C and runing on Red Hat Linux. In my code I have written a command that is fired on the linux shell by using system() function call. Now I need to read the output of this command in my c program and assign it to a variable. Can anyone... (1 Reply)
Discussion started by: shamik
1 Replies

9. Shell Programming and Scripting

have a shell script done in pl/sql and want output in html

I have this shell script where I have both pl/sql and sql. But want to have a snigle output file where the result of each cursors are in HTML tables. I was able to do that on my old script but it was only sql scripts (no pl/sql). Can I do have such outputs now with my new script where I... (2 Replies)
Discussion started by: arobert
2 Replies

10. Shell Programming and Scripting

to print output using shell command

suppose u have 2 files ; where both files have one line in common. say one file like that >gi|62859953|ref|NP_001017322.1| plexin B2 MKEKERTKAITEIYLTRLLSVKGTLQQFVDNFFQSVLNSNQVVPPAVKYFFDFLDEQAEKYEIKDEDTVHIWKTNSLSLR... (13 Replies)
Discussion started by: cdfd123
13 Replies
Login or Register to Ask a Question