[英]How to change bg color of column based on column values in HTML
I have a text file which get the server info whether UP/Down for a given time period with entries like: 我有一个文本文件,它使用以下条目获取服务器信息:在给定的时间段内是否向上/向下:
Server1 UP DOWN UP Down UP UP Down
Server2 Down UP Down Up UP Down Down
Here is the shell script which converts the above text file to a HTML page. 这是将上述文本文件转换为HTML页面的Shell脚本。
awk 'BEGIN{print "<html>\n<head>\n <style>\n table,th,td \n{\n border:1px solid black;border-collapse:collapse;n}\n</style>\n</head>\n<Body>\n<table><tr></tr> "
}
{
print "<tr>"
for(i=1;i<=NF;i++)
print "<td>" $i"</td>"
print "</tr>"
}
END{
print "\n</table>\n</Body>\n</html>\n"
}' testresult.txt > /var/www/html/test.html
while converting the text contents to HTML, I need the HTML cells background to be colored to RED when the entry is "Down" and to GREEN when server is "UP" 在将文本内容转换为HTML时,我需要将HTML单元格背景的颜色在条目为“ Down”时变为红色,在服务器为“ UP”时变为绿色。
I have tried to include an If statement inside the for loop for matching the text values with UP/Down. 我试图在for循环中包含一个If语句,以使文本值与UP / Down匹配。 But in vain.Could you please suggest where I am missing and is there any other way i could try?
但是徒劳无功。请您指出我失踪的地方,还有其他方法可以尝试吗?
Replace 更换
for(i=1;i<=NF;i++)
print "<td>" $i"</td>"
with 与
for(i=1;i<=NF;i++)
print "<td class = 'style" $i "'>" $i"</td>"
Then add to your css 然后添加到您的CSS
.styleDown {background-color: red;}
.styleUP {background-color: green;}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.