How HTML works in awk command in shell scripting?

2019-03-03 10:53发布

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 3 records for example).

mail output I am getting is: (10 cols)

DATE  FEED    FILE_NAME   JOB_NAME SCHEDULED TIME SIZE COUNT STATUS 
Dec 17 INVEST     iai     guxmow080 TUE-SAT 02:03 0.4248 4031 On_Time
Dec 17 SECURITIES amltxn  gdcpl3392 TUE-SAT 02:03 0.0015 9    Delayed
Dec 17 CONNECTED amlbene  gdcpl3392 TUE-SAT 02:03 0.0001 1    No_Records

output with perfect coloring: (6 cols only)

DATE  FEED    FILE_NAME   JOB_NAME SCHEDULED TIME SIZE COUNT STATUS 
Dec 17 INVEST     iai     guxmow080 On_Time(green color)
Dec 17 SECURITIES amltxn  gdcpl3392 Delayed(red color)
Dec 17 CONNECTED amlbene  gdcpl3392 No_Records(yellow color)

I am implementing coloring for Delayed, On_Time and No_Records field and I wrote below script which gives me bottom output.

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"

Dummy=$0
sub("[^ ]+$","",Dummy)
print Dummy "<span style=\"color:" color (bold ? ";font-weight:bold" : "")(size ? ";font-size:size" : "") (italic ? ";font-style:italic" : "") "\">" $NF "</span>"

}

END {
print "</pre>" \
"</body>" \
"</html>"
}
' output.txt > output.html

There are 4 columns are skipped automatically.

1条回答
贼婆χ
2楼-- · 2019-03-03 11:25

| date | feed_names | file_names | job_names | scheduled_time| timestamp| size| count| status |

Dec 19 ISS_BENEFICIAL_OWNERS_FEED amlcpbo_iss_20161219.txt gdcpl3392_uxmow080_ori_isz_dat WEEK_DAYS 00:03 9.3734 34758 On_Time

Dec 19 ISS_INVESTORS_FEED amlinvest_iss_20161219.txt gdcpl3392_uxmow080_ori_isz_dat WEEK_DAYS 00:01 0.0283 82 On_Time

Dec 19 ISS_TRANSACTIONS_FEED amltran_iss_1_20161219.txt gdcpl3392_uxmow080_ori_isz_dat WEEK_DAYS 00:12 14.022 36532 DELAYED

Dec 19 ISS_TRANSACTIONS_FEED amltran_iss_5_20161219.txt gdcpl3392_uxmow080_ori_isz_dat WEEK_DAYS 00:23 0.0010 3 DELAYED

Dec 19 IBS_CUSTOMER_FEED ibscust_aml_***_20161219.txt gdcpl3392_uxmow080_ori_sfp_ibc WEEK_DAYS (11 _out_of_11) -NA- ARRIVED

Dec 19 IBS_DDA_NOSTRO_ACCOUNT_FEED ibsacct_aml_***_20161219.txt gdcpl3392_uxmow080_ori_sfp_ibc WEEK_DAYS (44 _out_of_44) -NA- ARRIVED

Dec 19 GP__TRANSACTIONS_FEED amltrans__20161219.txt gdcpl3392_uxmow080_ori_sfp_glo WEEK_DAYS (3 _out_of_30) -NA- ARRIVED

But when I am trying to print in a sequential order by using below command
awk '{printf("%-5s%s\t%-33s%-35s%-39s%s\t%s%-3s\t%s\t%s\n", $1,$2,$3,$4,$5,$6,$7,$8,$9,$10)}' output.txt, I am getting the output in a sequential format but 4 cols are skipped. Kindly suggest!!!

| date | feed_names | file_names | job_names | scheduled_time| timestamp| size| count| status |

Dec 19 ISS_BENEFICIAL_OWNERS_FEED amlcpbo_iss_20161219.txt gdcpl3392_uxmow080_ori_isz_dat On_Time

Dec 19 ISS_INVESTORS_FEED amlinvest_iss_20161219.txt gdcpl3392_uxmow080_ori_isz_dat On_Time

Dec 19 ISS_TRANSACTIONS_FEED amltran_iss_1_20161219.txt gdcpl3392_uxmow080_ori_isz_dat DELAYED

Dec 19 ISS_TRANSACTIONS_FEED amltran_iss_5_20161219.txt gdcpl3392_uxmow080_ori_isz_dat DELAYED

Dec 19 IBS_CUSTOMER_FEED ibscust_aml_***_20161219.txt gdcpl3392_uxmow080_ori_sfp_ibc ARRIVED

Dec 19 IBS_DDA_NOSTRO_ACCOUNT_FEED ibsacct_aml_***_20161219.txt gdcpl3392_uxmow080_ori_sfp_ibc ARRIVED

Dec 19 GP__TRANSACTIONS_FEED amltrans__20161219.txt gdcpl3392_uxmow080_ori_sfp_glo YET_TO_RECEIVE

查看更多
登录 后发表回答