Space moving to next column (awk HTML)

Hi

I have create a report and have converted the text output to HTML but in the output there is a sentence "The transaction was aborted by the user.", the spaces between this sentence is considered as separate column.

How can I overcome the same?

I am providing my code, text output and HTML output.

Code my using

awk '
        BEGIN {
                print "From: "
                print "To: "
                print "MIME-Version: 1.0"
                print "Content-Type: text/html"
                print "Subject: CPU Used By Aborting session Report"
                print "<html><body></br></br>The report provides the list of user who has aborted their queries."
                print "<table border=1 cellspacing=1 cellpadding=1>"
        }
        !/^#/ && /^S/ {
                print "<tr>"
                for ( i = 1; i <= NF; i++ )
                        print "<td><b>" $i "<b></td>"
                print "</tr>"
        }
        !/^#/ && !/^S/ {
                print "<tr>"
                for ( i = 1; i <= NF; i++ )
                        print "<td>" $i "</td>"
                print "</tr>"
        }
        END {
                print "</table></body></html>"
        }
' /Reports/output/CPUAbortUser.txt | /usr/sbin/sendmail -t

Text out put

UserName       TotalCPU        AbortCount  AbortType         ErrorCode  ErrorText
MEHROTSQ     12,392.196           3    UserAborted           2,646    No more spool space in mehrotsq.
SHAFFERD      3,188.172             2    UserAborted           3,110    The transaction was aborted by the user.
ANKIREPA         2.876                2    UserAborted           3,110    The transaction was aborted by the user.
CHANDEVI          0.812               3    UserAborted           3,110    The transaction was aborted by the user.
DAIJI             0.476                   2    UserAborted           3,110    The transaction was aborted by the user.
DASMA            0.396                  2    UserAborted           3,110    The transaction was aborted by the user.

HTML output Image is attached

What is the field separator in your data file? If it's multiple spaces, it'll be difficult, as those spaces would cast / split the text as well into several fields. Can you change it, e.g. set it to <TAB> chars?

Previously the text output was having " | " as delimiter.
The output was again distorted. Please check the attached image.

Seeming like there is something am missing in the code.

Did you adapt the input field separator in your script?

Without seeing some sample input it is impossible to test what might be going wrong, but two things seem to be problematic in your code.

Shouldn't:

                        print "<td><b>" $i "<b></td>"

be:

                        print "<td><b>" $i "</b></td>"

?

And, you can't use the default awk input field separator if something other than a single <space> character is your input field separator and there are <space> characters in your last input field. Since you haven't shown us the contents of /Reports/output/CPUAbortUser.txt we don't have any way to make a reasonable guess as to what your actual field separators are. If you would clearly define your input file format, we could help you correctly set FS or rewrite your conversion loops to use one input field for each of the first five output fields and another loop to gather the remaining input fields into a single output field for the ErrorText heading.

I will disagree slightly with RudiC about having multiple spaces as your input field separator. If your input has multiple <space> characters between fields and single <space> characters as data inside a field, you can just change the first line of your awk script from:

awk '

to:

awk -F'  +' '

along with the change suggested above, and everything might work for you.

Hi Don,

Your suggestion " awk -F' +' ' " did worked properly, The column is not getting distorted but the header shifted by one column.
Please find the attached output.
Is it possible to get the header align.

Output file information:

Currently there is no delimiter in output file. The tab between column is delimiter.
I can surely insert " | "delimiter in file. Here is how the file will appear after having delimiter but the tab will still be there. I cannot get rid of tabs.

UserName                  |                TotalCPU|      AbortCount|AbortType  |     ErrorCode|ErrorText
MEHROTSQ                 |              26,582.268|               2|UserAborted|         2,646|No more spool space in mehrotsq.
KOCHSR                    |              13,249.964|               2|UserAborted|         3,110|The transaction was aborted by the user.
TUMLISJZ                  |               9,171.452|               3|UserAborted|         3,110|The transaction was aborted by the user.
GILLILPE                   |               1,333.848|               1|UserAborted|         3,110|The transaction was aborted by the user.
HARDIKAR                 |                   0.556|               2|UserAborted|         2,646|No more spool space in hardikar.

Having Tab and | delimiter is more trouble to handle.

The header entry WDNAME "shifts" the header fields but doesn't seem to be part of the data - where did it come from?
You are saying "The tab between column is delimiter" - does this mean there in fact ARE <TAB>s separating fields?

The issue is resolved
The output file is change to have pipe as delimiter and made code change

awk -F '|' '

.

Thanks Rudi for you time.

Thank a lot Don for time and suggestion; helping me and rectifying where my code was going wrong.