Output in table format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Output in table format
# 1  
Old 04-16-2014
Output in table format

I have one script which generate file called report.txt having following output

Code:
parameter_name status comment
banking ok NA
finance 30% hike NA
Loan_department ok 20%
HR_Group defaulters Ajay

I wanted to convert this file into tabular form.
You can see each line contain 3 words and they are separated by single space.

So to covert it into table i use following command
Code:
awk '{printf "%-30s|%-18s|%-20s\n",$1,$2,$3}'  report.txt > final_report.txt

final_report.txt looks like

Code:
parameter_name                |status            |comment
banking                       |ok                |NA
finance                       |30%               |hike
Loan_department               |ok                |20%
HR_Group                      |defaulters        |Ajay

When i send this file to my mail using mailx command the columns get disturbed from their original position.
and output become difficult to read though on UNIX box it is wel formatted.

Is there any other way to convert this report.txt file into tabular form.
Also converted file should look good and undisturbed when I send that file to my mail ID by mailx command.
# 2  
Old 04-16-2014
The result depends on how the receiving mail program displays a text only mail, some use a fixed width font, others a variable width font.

The solution for this issue is described here.
This User Gave Thanks to hergp For This Post:
# 3  
Old 04-16-2014
you can use the below code to convert your data into HTML table
Code:
awk 'BEGIN {print "<table>"}
  {print "<tr>"; for(i = 1; i <= NF; i++) print "<td>" $i "</td>"; print "</tr>"}
  END {print "</table>"}' report.txt > report.html

and send this using 'sendmail' command provided by hergp
This User Gave Thanks to SriniShoo For This Post:
# 4  
Old 04-16-2014
Hi.

See also post #14 in thread https://www.unix.com/shell-programmin...ce-script.html for a perl solution to create tables from text to formats in ASCII, HTML, and bbcode.

Best wishes ... cheers, drl
This User Gave Thanks to drl For This Post:
# 5  
Old 04-17-2014
Thank you drl,

Hi drl,
Thanks for your help
I saw your code in link provided by you.
I tried a few combinations. But probably i am doing something wrong.
Can you give me the code for above problem.? Also i am not sure whether PERL code can work on HP-UX server. I am not much familiar with perl.
your code that gives colorful output is excellent. Can you give me same for this problem.? i am using HP-UX server

Thanks in advance Smilie
# 6  
Old 04-17-2014
Hi, Nakul_sh.

The HP system to which I have access is:
Code:
OS, ker|rel, machine: HP-UX, B.11.11, 9000/785

and the perl version there is:
Code:
$ perl -v

This is perl, v5.10.1 (*) built for PA-RISC2.0
...

Before we go any farther, please post the version of HP-UX you are using, and the version of perl on that machine ... cheers, drl
# 7  
Old 04-17-2014
Hi drl

hi drl,
seems that perl is available for me but i am very new to perl scripting.
Can you give me the exact code to resolve this problem.? I have generated .html file by using the code provided by you.
Can you give me further code to convert HTML file into a colorful table?
I saw the user Chubler_XL have given a code in below link
Color encoding on the disk space script
But i am not able to convert this code to suit my requirement.
I will be thankful to you if you could help. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell output format like table

Hi, OS: Redhat 7.5 shell: Bash Wrote below script to login into oracle via shell script and trying to reset locked account..It works as expected. But I need specific output << EOF should go to target terminal not all out put running below script from ansible command line.. #!/bin/bash... (1 Reply)
Discussion started by: onenessboy
1 Replies

2. Shell Programming and Scripting

How to create a file from output of vertica table query in UTF-8 format?

Hello, In my shell script, I extract table data from HP Vertica DB into a csv file using vsql -c command. But the problem is the file getting created is in binary format and hence some of the data becomes unreadable which has chinese characters as part of data. file -i filename.csv - gives... (2 Replies)
Discussion started by: Dharmatheja
2 Replies

3. Shell Programming and Scripting

Arranging the command output into an html table format

Hi, I need to format a command output for the beolow command: runmqckm -cert -list -db $MQ_KDB -pw $PASSWD -expiry $EXP | grep -v "Certificates in database" The output will be: "ABC - cert name" From: Tuesday, May 25, 1999 11:09:40 AM CDT To: Saturday, May 25, 2019 11:39:40 AM CDT ... (3 Replies)
Discussion started by: bdpl
3 Replies

4. Shell Programming and Scripting

Need the output in the mentioned Table format

Hi Friends, I have the script output like below: Script Output: ----------------------------------------------------------------------- Details of the Client: ----------------------- name: server1; save set: All; ... (3 Replies)
Discussion started by: akmani
3 Replies

5. Shell Programming and Scripting

I want query output to send on mail using table tag and output should be in table

#! /bin/ksh #] && . ./.profile 2>/dev/null if test -f '.profile'; then . ./.profile; fi; #. .profile LOG_DIR=/app/rpx/jobs/scripts/just/logs sendEmail() { pzCType="$1"; pzTitle="$2"; pzMsg="$3"; pzFrom="$4"; pzTo="$5"; pzFiles="$6"; pzReplyTo="$7" ( ... (21 Replies)
Discussion started by: ankit.mca.aaidu
21 Replies

6. Shell Programming and Scripting

Normal text to table format

Hi, I am trying to show my list, from a simple list format to a table (row and column formatted table) Currently i have this format in my output (the formart it will always be like this ) >> first 3 lines must be on the same line aligned, and the next 3 shud be on 2nd line....: INT1:... (10 Replies)
Discussion started by: eboye
10 Replies

7. Shell Programming and Scripting

convert the output in table format

Hi All, I have a output like below values val1=test.com val2=10.26.208.11 val3=en1 val4=test-priv1.com val5=192.168.3.4 val6=en2 val7=test-priv2.com val8=192.168.4.4 val9=en3 val10=test-vip.com val11=10.26.208.9 val12=$val3 I want to convet this output values into below... (1 Reply)
Discussion started by: kamauv234
1 Replies

8. Shell Programming and Scripting

Help with perl script to output data in table format...

Hello, I need help with a perl script that will process a text file and match virtual server name to profile(s). the rest will be ignored. Virtual server name follows the word "virtual" in the begging of the line. There could be multiple profiles assigned to one virtual server. For example, ... (3 Replies)
Discussion started by: besogon
3 Replies

9. Shell Programming and Scripting

Table format

My Code Hi Friends, I need to get output in table format using unix shell script.For example my server CPU and memory utilization report will come as a mail with ordinary format but i want to make as table format. Here two output finally we are getting:- CPU utilization is... (2 Replies)
Discussion started by: susindram
2 Replies

10. Programming

Create table with date format.

Hello, Could you please let me know the correct format of CREATE TABLE statement with DATE format. CREATE TABLE EMP_TABLE1 ( NAME VARCHAR(6) PRIMARY KEY, ADDRESS VARCHAR(6), BIRTH_DATE DATE ); I want BIRTH_DATE to be in "YYYYMMDDHHMISS" format. How we can create table with... (4 Replies)
Discussion started by: Poonamol
4 Replies
Login or Register to Ask a Question