0

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.

11
  • Your script works perfectly for me (copy pasted it). Are you sure output.txt is the right format? This was checked before the edit with Dummy. Commented Dec 18, 2016 at 15:15
  • @kabanus, Hello Sir, I guess so coz I printed all 10 cols using awk as below 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 Commented Dec 18, 2016 at 15:17
  • If $7-10 don't exist that will still work. Can you copy paste the first 4 lines of output.txt as they are (not using awk or anything)? The new version duplicates lines but still shows all columns for me. Commented Dec 18, 2016 at 15:27
  • Here are 4 lines Dec 18 ENTITY Lux_Entity uxmow080 DAILY 07:01 0.0003 2 DELAYED Dec 18 FUND Lux_Fund uxmow080 DAILY 07:01 0.0008 2 ON_Time Dec 18 SEC Lux_Investment uxmow080 DAILY 07:01 0.0002 2 DELAYED Dec 18 INVEST Lux_Investor uxmow080 DAILY 07:01 0.0006 2 DELAYED Commented Dec 18, 2016 at 16:15
  • Weird as heck. Try putting #!/bin/bash at the top, I'm using bash so maybe that's it though it shouldn't matter. Commented Dec 18, 2016 at 18:17

1 Answer 1

1

| 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

Sign up to request clarification or add additional context in comments.

2 Comments

Move all of that into your question and use the editors {} button to format the input/output properly like you did for your code sample. Did you try my suggestion of running dos2unix or similar on the input file?
This question is related to another one, created by means of another user name. Do not hope your solutions to be rewarded by the OP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.