I have a script called "main.ksh" which returns "output.txt" file and I am sending that file via mail.(list contains 50+ records, I just give 4 records for example)
mail output I am getting is:
DATE | FEED NAMEs | FILE NAMEs | JOB NAMEs | SCHEDULED_TIME| TIMESTAMP| SIZE(MB)| COUNT| STATUS |
Dec 17 INVEST_AI_FUNDS_FEED amlfunds_iai_20161217.txt gdcpl3392_uxmow080_ori_inv_ai TUE-SAT 02:03 0.4248 4031 On_Time
Dec 17 INVEST_AI_SECURITIES_FEED amltxn_iai_20161217.txt gdcpl3392_uxmow080_ori_inv_ai TUE-SAT 02:03 0.0015 9 On_Time
Dec 17 INVEST_AI_CONNECTED_PARTIES_FEED amlbene_iai_20161217.txt gdcpl3392_uxmow080_ori_inv_ai TUE-SAT 02:03 0.0001 1 No_Records
I am implementing coloring for Delayed,On_Time and No_Records field and I wrote below script which gives me bottom output(output is correct but there is no space separated).
awk 'BEGIN {
print "<html>" \
"<body bgcolor=\"#333\" text=\"#f3f3f3\">" \
"<pre>"
}
NR == 1 { print $0 }
NR > 1 {
if ($NF == "Delayed") color="red"
else if ($NF == "On_time") color="green"
else if ($NF == "No_records") color="yellow"
else color="#003abc"
$NF="<span style=\"color:" color "\">" $NF "</span>"
print $0
}
END {
print "</pre>" \
"</body>" \
"</html>"
}
' output.txt > output.html
output with perfect coloring:
| DATE | FEED NAMEs | FILE NAMEs | JOB NAMEs | SCHEDULED_TIME| TIMESTAMP| SIZE(MB)| COUNT| STATUS |
Dec 17 INVEST_AI_FUNDS_FEED amlfunds_iai_20161217.txt gdcpl3392_uxmow080_ori_inv_ai On_Time
Dec 17 INVEST_AI_SECURITIES_FEED amltxn_iai_20161217.txt gdcpl3392_uxmow080_ori_inv_ai On_Time
Dec 17 INVEST_AI_CONNECTED_PARTIES_FEED amlbene_iai_20161217.txt gdcpl3392_uxmow080_ori_inv_ai No_Records
There are 4 columns are skipped automatically. Could you please help me on this please ? Thanks a lot !
$NF="<span style=\"color:" color "\">" $NF "</span>". In the man pages of awk you can read:Assigning a value to an existing field causes the whole record to be rebuilt when $0 is referenced.<pre>tag using AWK'ssprintf(), orprintf():awk '{ printf("%-20s%15s", $1, $2) }' <<< 'abc 123', or build a table. Not necessarily using the<table>tag. You can build a table using only<div>s and CSS.\0, and/. By default, AWK splits the lines into fields by spaces. You can pass another delimiter with-Foption. It could be/, for instance. But how do you know that the rest of the fields won't contain a slash? I mean that the input format is far from perfect for this task. I'd suggest XML, or JSON, or any other kind of strict format.