Need help shell+awk+html


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help shell+awk+html
# 1  
Old 11-30-2011
Need help shell+awk+html

Hi,

Can someone help me how to add header cell in html table if i use the script posted below?

I use shell script to search in files and format output into html table.

/bin/zcat /CDR/cdr_TC/calllogs*_*_$FORM_data*.gz | sed 's/[:]/;/g' | awk -F";" '{if($1~/'$FORM_msgid'/ && $2~/'$FORM_origpdu'/) print $0 | awk -F";" 'BEGIN{print "<table>"} { print "<tr>"; print "<th> msgid</th>";print "<th> origpdu</th>";print "</tr>";print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}'

but the header cell appears on top of each row.

<table>
<tr>
<th> msgid</th>
<th> origpdu</th>
</tr>
<tr>
<td>237366092</td>
<td> 1</td>
</tr>
<tr>
<th> msgid</th>
<th> origpdu</th>
</tr>
<tr>
<td>237366092</td>
<td> 0</td>
</tr>
<tr>
<th> msgid</th>
<th> origpdu</th>
</tr>
<tr>
<td>237366092</td>
<td> 0</td>
</tr>
</table>
# 2  
Old 11-30-2011
Could you post the format of expected output..?
# 3  
Old 11-30-2011
Thak you for your quick responce.

I expect

msgid origpdu
237366092 1
237366092 0
237366092 0
but i the result is

msgid origpdu
237366092 1
msgid origpdu
237366092 0
msgid origpdu
237366092 0
# 4  
Old 11-30-2011
i' m not clear about your input but if it is like

Code:
# cat input
<table>
<tr>
<th> msgid</th>
<th> origpdu</th>
</tr>
<tr>
<td>237366092</td>
<td> 1</td>
</tr>
<tr>
<th> msgid</th>
<th> origpdu</th>
</tr>
<tr>
<td>237366092</td>
<td> 0</td>
</tr>
<tr>
<th> msgid</th>
<th> origpdu</th>
</tr>
<tr>
<td>237366092</td>
<td> 0</td>
</tr>
</table>

Code:
# sed '/^$/d;;:x;N;s/<[^>]*>\|  *\|\n/ /g;tx' input|awk '{split($0,a);for(i=1;i<NF;i++){
if(a[i]~/[a-z]/&&w!=1){b[x++]=a[i]" "a[++i];w=1}
else if(a[i]!~/[a-z]/){b[x++]=a[i]" "a[++i]};}
for(j=0;j<length(b);j++){print b[j]}}'
msgid origpdu
237366092 1
237366092 0
237366092 0

regards
ygemici
# 5  
Old 12-01-2011
Hi ygemici,
thank you for your suggestion but my inpit is like
Code:
zcat calllogs*_*_$FORM_data*.gz
107D81EA4;1:1
1085AA51D;3:1
237366092;1:1
1085AA51D;3:1
237366092;0:1
107A2210D;0:1
1085AA520;3:1
1085AA524;0:1
107D81EA7;1:1
1085AA523;0:1
237366092;0:1
107D81EA8;1:1
107D81EA8;1:1
1074A2240;3:1
1074A225F;3:1
107D81EAA;1:1

1.Read file
Code:
/bin/zcat /CDR/cdr_TC/calllogs*_*_$FORM_data*.gz |

2. Substitute all ":" with ";"
Code:
sed 's/[:]/;/g' |

3.Search for string
Code:
awk -F";" '{if($1~/'$FORM_msgid'/ && $2~/'$FORM_origpdu'/) print $0 |

4. Convert the output in HTML table
Code:
awk -F";" 'BEGIN{print "<table>"} { print "<tr>"; print  "<th> msgid</th>";print "<th>  origpdu</th>";print "</tr>";print  "<tr>";for(i=1;i<=NF;i++)print "<td>"  $i"</td>";print "</tr>"} END{print "</table>"}'

It works fine but in the output table header cells appear before each row like table below
msgid origpdu
237366092 1
msgid origpdu
237366092 0
msgid origpdu
237366092 0
and i want header cells to be only in the first row like table below
msgid origpdu
237366092 1
237366092 0
237366092 0
# 6  
Old 12-01-2011
hi vasil
what is your output after that?
Code:
/bin/zcat /CDR/cdr_TC/calllogs*_*_$FORM_data*.gz |sed 's/[:]/;/g' |awk -F";" '{if($1~/'$FORM_msgid'/ && $2~/'$FORM_origpdu'/) print $0}'

# 7  
Old 12-02-2011
Hi ygemici
Below is the output from the command
Code:
[user@OMCTC cdr_TC]$ /bin/zcat /CDR/cdr_TC/callogs*_*_20111201*.gz |sed 's/[:]/;/g' |awk -F";" '{if($1~/1/ && $2~/1/) print $0}' | more

1146D92DF    1    4
1146DF29F    1    2
11484C213    1    2
11484C214    1    4
1146DF2A0    1    2
11484C213    1    2
1146E489A    1    4
1146D92E2    1    2
11484C215    1    4
11484C216    1    2
11484C218    1    4
1146D92E1    1    2
11484C219    1    2
11484C21A    1    2
1146DF2A7    1    2
11484C21B    1    2
11484C21B    1    2
1146E489F    1    2
11484C21C    1    2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk to extract value after keyword in html

Using awk to extract value after a keyword in an html, and store in ts. The awk does execute but ts is empty. I use the tag as a delimiter and the keyword as a pattern, but there probably is a better way. Thank you :). file <html><head><title>xxxxxx xxxxx</title><style type="text/css"> ... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. UNIX for Beginners Questions & Answers

Html output with awk/sendmail

Hello All, I inherited maintenance of a script that uses awk on an input file (space delimited) and formats it into an html table and send out using sendmail. I know how to manipulate the print statements to add columns and rows, however that is the extent of my html knowlege. I've searched... (5 Replies)
Discussion started by: Big-J
5 Replies

3. UNIX for Beginners Questions & Answers

awk HTML Conditional Formating

I am receiving the below output in text format. The output is converted to HTML table using the code mentioned below output in text LogDate DayOfWeek/Hours _0_ _1_ _2_ _3_ _4_ _5_ _6_ _7_ _8_ _9_ _10_ _11_ _12_ _13_ _14_ _15_ _16_ ... (3 Replies)
Discussion started by: Dumpi16
3 Replies

4. Shell Programming and Scripting

Help with awk and html

Hi i have a file say test with the following output server share-name path acl ---------- ----------------------------... (2 Replies)
Discussion started by: venkitesh
2 Replies

5. Shell Programming and Scripting

Awk/sed HTML extract

I'm extracting text between table tags in HTML <th><a href="/wiki/Buick_LeSabre" title="Buick LeSabre">Buick LeSabre</a></th> using this: awk -F "</*th>" '/<\/*th>/ {print $2}' auto2 > auto3 then this (text between a href): sed -e 's/\(<*>\)//g' auto3 > auto4 How to shorten this into one... (8 Replies)
Discussion started by: p1ne
8 Replies

6. Shell Programming and Scripting

Help in using html in Shell script

Hi, I made a script that displays various fileds of report that are required in csv format and send it on mail(the csv file). Now I want to convert the csv format into html table and then send it on mail. Reports_Output.csv Code:... (6 Replies)
Discussion started by: Supriya Singh
6 Replies

7. Shell Programming and Scripting

awk to parse html file

Is it possible in awk to parse a webpage (EDAR Gene Sequencing - Genetic Testing Company | The DNA Diagnostic Experts | GeneDx), the source code is attached. <title> EDAR Gene Sequencing <dt>Test Code:</dt> <dd>156 </dd> <dt>Turnaround Time:</dt> <dd>6-8 weeks </dd> ... (4 Replies)
Discussion started by: cmccabe
4 Replies

8. Shell Programming and Scripting

awk help for HTML

Hi all, I have a file as below input.csv NAME,EMPNO,PHNO kkk,1234,0000 nnn,456,8765 hhh,888,555 hhy,222,567 i want to convert this into HTML table im using this awk -F"," 'BEGIN{print "<table border=1>" { print "<tr>";for(i=1;i<=NF;i++)print "<td><b><font face=\"verdana\"><font... (1 Reply)
Discussion started by: zozoo
1 Replies

9. Shell Programming and Scripting

html formatting using awk

Hi I have a file as given below: <table border=1> <TR><TH>Script Name</TH><TH>CVS Status</TH><TH>Script Location</TH></TR> <TR><TD><CENTER>Work Area: /home/ustst/</CENTER></TD></TR> <TR><TD><CENTER>admin_export.sh</CENTER></TD><TD><CENTER>Locally... (1 Reply)
Discussion started by: sudvishw
1 Replies

10. Shell Programming and Scripting

SHELL SCRIPT AND HTML

Hello I'm trying to develop a shell script that executes commands such as cat / etc / fstab uname, etc. ..... which generates me an output file format html own way. Currently the shell script with the commands there, I have some notions of html but the generation of my html file is not clean at... (2 Replies)
Discussion started by: ddtseb
2 Replies
Login or Register to Ask a Question