Space moving to next column (awk HTML)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Space moving to next column (awk HTML)
# 1  
Old 05-23-2018
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
Code:
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

Code:
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



Moderator's Comments:
Mod Comment Seriously: Please use CODE tags as required by forum rules!


Space moving to next column (awk HTML)-html-outputjpg

Last edited by RudiC; 05-23-2018 at 08:02 AM.. Reason: Added CODE tags.
# 2  
Old 05-23-2018
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?
# 3  
Old 05-23-2018
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.
Space moving to next column (awk HTML)-delimiter-html-outputjpg

Last edited by Dumpi16; 05-23-2018 at 10:22 AM.. Reason: adding more detilas
# 4  
Old 05-23-2018
Did you adapt the input field separator in your script?
# 5  
Old 05-23-2018
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:
Code:
                        print "<td><b>" $i "<b></td>"

be:
Code:
                        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:
Code:
awk '

to:
Code:
awk -F'  +' '

along with the change suggested above, and everything might work for you.
# 6  
Old 05-23-2018
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.

Code:
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.


Moderator's Comments:
Mod Comment Please use CODE tags (far data as well!) as required by forum rules!
Space moving to next column (awk HTML)-html-outputjpg

Last edited by RudiC; 05-23-2018 at 11:54 AM.. Reason: Added CODE tags.
# 7  
Old 05-23-2018
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Create the space only in the Third column by awk

Hi All , I am having an input file like this Input file r s e y Pin Numbers s n eppppppppppppppppppc ... (3 Replies)
Discussion started by: kshitij
3 Replies

2. UNIX for Beginners Questions & Answers

Help with moving list of data to 2nd column of HTML file

Hi Team, Can you help me with writing shell script to printing the list output to 2nd column in HTML file. (2 Replies)
Discussion started by: veereshshenoy
2 Replies

3. UNIX for Advanced & Expert Users

Need to remove leading space from awk statement space from calculation

I created a awk state to calculate the number of success however when the query runs it has a leading zero. Any ideas on how to remove the leading zero from the calculation? Here is my query: cat myfile.log | grep | awk '{print $2,$3,$7,$11,$15,$19,$23,$27,$31,$35($19/$15*100)}' 02:00:00... (1 Reply)
Discussion started by: bizomb
1 Replies

4. Red Hat

On CentOS, moving space from large free directory to another

Hi. My "/usr" folder is running out of space. My "/home" folder is quite large and has a lot of free space. As follows: Filesystem Type Size Used Avail Use% Mounted on ... /dev/sda5 ext3 9.7G 2.6G 6.7G 28% / /dev/sda7 ext3 152G 16G 128G 11% /home /dev/sda3 ... (7 Replies)
Discussion started by: pkiula
7 Replies

5. Shell Programming and Scripting

Moving a column across a delimited data file

Hi, I am trying to move a column from one position to another position in a delimited file. The positions are dynamic in nature and are available by environmental variables. Also the file can have n number of columns. Example: Initial Column Position=1 Final Column Position=3 Delimiter='|' ... (2 Replies)
Discussion started by: ayan153
2 Replies

6. AIX

Moving free space from one LV to another LV

in the same VG? Is there a way we can do this? We basically have a test server that used to be a production server. Now the newly created test directories have run out of space and the old production directories have alot of free space. Can we transfer that free space over? If so how? Have... (2 Replies)
Discussion started by: NycUnxer
2 Replies

7. Shell Programming and Scripting

Moving files with space, in for loop

Hi All I need to put a bunch of specific files in a directory (with loads of other files), into a tar archive. The best way I thought of doing this was putting the filenames into a file, reading them line by line in a for loop, and then adding them to a tar acrhive. However the filenames have... (6 Replies)
Discussion started by: saabir
6 Replies

8. Shell Programming and Scripting

Replace space, that is not in html tags <> with new line using sed

Hi, I am working on transforming html code text into the .vert text format. I want to use linux utility sed. I have this regexp which should do the work: s/ \(?!*>\)/\n/g. I use it like this with sed: echo "you <we try> there" | sed 's/ \(?!*>\)/\n/g' ... The demanded output should be: you <we... (5 Replies)
Discussion started by: matt1311
5 Replies

9. UNIX for Advanced & Expert Users

moving space from one partition to another

How can I move some space allocated to one partition to another, i.e. from "/var" to "/" . Thanks! (4 Replies)
Discussion started by: jason6792
4 Replies

10. UNIX for Dummies Questions & Answers

Moving .html files while preserving hyperlink integrity?

Hi, I use a Windows-based program called <a href="http://www.coast.com">Coast Webmaster</a> for moving large numbers of HTML files in one directory to another directory. As you drag and drop each file or entire directory of files to new locations in the web root directory tree, this utility... (1 Reply)
Discussion started by: Buddy123
1 Replies
Login or Register to Ask a Question