Issues with awk scripting for HTML tags


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issues with awk scripting for HTML tags
# 1  
Old 07-29-2018
Issues with awk scripting for HTML tags

Below is the data file(results) contents-
Code:
13450708,13470474,US,15

24954,24845,JPN,44

14258992,14365059,US,4

24954,24845,IND,44

I want to send above data sets to email in a tabular format. For that I am using below awk script. Now the challenge I am facing here is - I want to make the background color as red if the lastfield in the datasets ( i.e. here 15,44,4,44) > 40. Can you please tell me how to use the same in below code.
Code:
awk 'BEGIN{

FS=","

print  "<HTML>""<TABLE border="1"><TH>Store_count</TH><TH>Store_sold</TH><TH>Store_code</TH><TH>Backlogs</TH>"

}

 {

printf "<TR>"

for(i=1;i<=NF;i++)

printf "<TD>%s</TD>", $i

print "</TR>"

 }

END{

print "</TABLE></BODY></HTML>"

 }

' results > file1.html

Moderator's Comments:
Mod Comment Please use code tags when posting code and data
# 2  
Old 07-29-2018
For HTML4 use bgcolor in the <BODY bgcolor=(1,2,3) header -

HTML body bgcolor Attribute

For HTML5 use CSS - bgcolor

Tryit Editor v3.5

Code:
<body style="background-color:powderblue;">

Be aware that not all browsers support HTML4.

Also, your example is missing the BODY header
# 3  
Old 07-29-2018
Quote:
Originally Posted by Roseline
code.
Code:
awk 'BEGIN{

FS=","

print  "<HTML>""<TABLE border="1"><TH>Store_count</TH><TH>Store_sold</TH><TH>Store_code</TH><TH>Backlogs</TH>"

}
....

I strongly recommend you not use table tags.

Better to use divs, even in email.

Also, I recommend you avoid any style attribute in your elements and instead include a small <style> tag with CSS; but I understand when you have just a small amount of style, why you would like to use the style attribute, but all the pros use CSS.
This User Gave Thanks to Neo For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sendmail with HTML body and attachment code issues

Hi, I was working on getting an HTML file in the mail body along with attaching a "csv" file to the mail. Below are the 2 parts of the code. I need help with the second part where I'm sending the mail. The HTML file as an attachment is perfect without any issues and with proper formatting.... (6 Replies)
Discussion started by: aster007
6 Replies

2. UNIX for Advanced & Expert Users

How to use HTML in UNIX Bash Scripting?

I am planning to run an automation , Could anyone try to help me to how to write an html in unix scripting so when I try to send email it should work especially with Bold and colors (6 Replies)
Discussion started by: cassia
6 Replies

3. Shell Programming and Scripting

Issues with scripting users

Hello everyone, I am new to the forum community and need help with some scripts. First off let me put that this is “NOT” a homework assignment as I have been given this information where I work (IUPUI-UITS) and need help on this since I have no experience in this area. The only reason I am turning... (1 Reply)
Discussion started by: wingzero89
1 Replies

4. Shell Programming and Scripting

Scripting users issues...

Hello everyone, I am new to the forum community and need help with some scripts. I have attached what I have so far and these are scripts that have been passed on to me for a project that I have been assigned. To tell the truth I have never really worked with scripts and have no clue how these even... (3 Replies)
Discussion started by: wingzero89
3 Replies

5. Shell Programming and Scripting

awk -- Extract data from html within multiple tags as reference

Hi, I'm trying to get some data from an html file, but the problem is before it can extract the information I have multiple patterns that need to be passed through. https://www.unix.com/shell-programming-scripting/150711-extract-data-awk-html-files.html Is a similar problem. The only... (5 Replies)
Discussion started by: counfhou
5 Replies

6. Shell Programming and Scripting

Removing all except couple of html tags from html file

I tried to find elegant (or at least simple) way to remove all but couple of html tags from html file, but all examples I found dealt with removing all the tags. The logic of the script would be: - if there is <li> or <ul> on the line, do nothing (=write same line to output) - if there is:... (0 Replies)
Discussion started by: juubuntu
0 Replies

7. Shell Programming and Scripting

Parsing HTML, get text between 2 HTML tags

Hi there, I'm quite new to the forum and shell scripting. I want to filter out the "166.0 points". The results, that i found in google / the forum search didn't helped me :( <a href="/user/test" class="headitem menu" style="color:rgb(83,186,224);">test</a><a href="/points" class="headitem... (1 Reply)
Discussion started by: Mysthik
1 Replies

8. Shell Programming and Scripting

how to use html tag in shell scripting

Hai friends I have a small doubt.. how can we use html tag in shell scripting code : echo "<html>" echo "<body>" echo " welcome to peace world " echo "</body>" echo "</html>" output displayed like this: <html> <body> welcome to peace world </body> </html> (5 Replies)
Discussion started by: jrex1983
5 Replies

9. UNIX for Dummies Questions & Answers

scripting issues...

Hi guys, I am thanks in advance for any posts and for reading. I am trying to run this script, under solaris: echo "****************************************" echo "The host is: " echo "****************************************" <<EOF find /etc/default -name login -exec ls -l {} \; find... (5 Replies)
Discussion started by: B14speedfreak
5 Replies

10. Shell Programming and Scripting

Shell scripting issues

hi, I am stuck in a shell script where in i need to extract the specific users from \etc\passwd file. Once this is done, i need to assign Roles to these users which are different for different users. What could be the optimum solution. If i hard code the Roles values in a text file, how would i... (1 Reply)
Discussion started by: ashutosh101
1 Replies
Login or Register to Ask a Question