Visit Our UNIX and Linux User Community


Dispaying output in tabular form


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Dispaying output in tabular form
# 1  
Old 09-11-2013
Dispaying output in tabular form

hi,

I have a script which is dispaying the output as below:

Code:
 
Column 3:value1
Column 4:value 4
column 8:value 8
column 9:value 9
column 13:value 13
Column 3:value10
Column 4:value 40
column 8:value 80
column 9:value 90
column 13:value 103

However,I need the output in tabular form as below
Code:
 
column 1 column 4 column 8 column 9 column 13
value 1 value4 value 8 value 9 value 13
value 10 value40 value 80 value 90 value 103

I am using below awk command for the above output but it is not coming in tabular form:

Code:
awk -F, '($13=="") {print "error"; exit 1}
(NR==1){h3=$3;h4=$4;h8=$8;h9=$9;h13=$13;next}
 (NF>1){print h3": "$3"\n"h4": "$4"\n"h8": "$8"\n"h9": "$9"\n"h13": "$13}
' $IFILE>>$OFILE


Last edited by Scott; 09-11-2013 at 08:31 PM.. Reason: Code tags for code too!
# 2  
Old 09-11-2013
I can see why it wouldn't work for you, when your data's separated by : and you're using , as a separator and you never have 13 columns but are checking for column 13!

Code:
awk -F: -v OFS="\t" -v W=4 '(++R)<=W { A=A OFS $1 ; B=B OFS $2 ; next }
{
        print substr(A, 2);
        print substr(B, 2);
        R=0;
}

END {
        if(R>0)
        {
               print substr(A,2);
               print substr(B,2);
        }
}' inputfile

# 3  
Old 09-11-2013
Is their any other simple way..I think we can use HTML tags or some different way.

---------- Post updated at 06:46 PM ---------- Previous update was at 06:43 PM ----------

I have field separator as , only and there are total 13 columns in file out of which I am displaying 5 columns.
# 4  
Old 09-11-2013
Please show us your input file and the output you want to see.

Showing us output you don't want, and the script that produces the output you don't want makes it hard for us to come up with a realistic test case to see if we can give you something that does what you do want.
# 5  
Old 09-12-2013
input file as below which is , separated.

Code:
 
column1,column2,column3,column4,column5,column6,column7
value1,value2,value3,value4,value5,value6,value7
value11,value21,value31,value41,value51,value61,value71

I am using the below command do get the output

Code:
 
IFILE=/home/home1/Report1
OFILE=/home/home1/`date +"%m%d%y%H%M%S"`.dat
if [ -r $IFILE ]  #Checks if file exists and readable
then
awk -F , 'int($6)!="0"||int($7)!="0" {printf "Colum1:                        %s\ncolumn2:                                 %s\ncolumn3:             %s\nFile column4:                                 %s\ncolumn5:              %s\ncolumn6 :       %s\nColumn7:    %s\n",$1,$2,$3,$4,$5,$6,$7}' $IFILE
fi

The above is giving output as below:
Code:
 
column1:value1
column2:value2

and so on

Code:
 
I need the output in tabular form
column1  column2  column3  column4  column5  column6  column7
value1      value2     value3    value4   value5   value6   value7
value11   value21     value31    value41   value51   value61   value71

I belive using HTML tags we cam do but not sure how can we use in my script.
# 6  
Old 09-12-2013
Since none of the data in your sample input file is numeric, the awk script you gave in the last message will produce absolutely no output.

If it did find non-zero data in fields 6 and 7 of your input file, the output would start with:
Code:
Colum1:                        value1

rather than:
Code:
column1:value1

When you drastically change your requirements between posts and give us sample input data, sample code, and sample output data that don't match, there isn't much incentive for us to try to guess what you really want nor to try to help you come up with a solution for your problem.

If you just want to print your input csv file as a tab separated table instead of converting it to a columnar form as done by your sample awk scripts, the simple thing to do is:
Code:
awk -F, '{$1=$1;print}' OFS='\t' "$IFILE"

which (with your sample input from your previous message) will produce the output:
Code:
column1	column2	column3	column4	column5	column6	column7
value1	value2	value3	value4	value5	value6	value7
value11	value21	value31	value41	value51	value61	value71


Previous Thread | Next Thread
Test Your Knowledge in Computers #136
Difficulty: Easy
The IEEE named Linus Torvalds as the recipient of the IEEE Computer Society's Computer Pioneer Award in 2014.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fetching the required data out of a tabular form

Hello Gurus, I am trying to fetch a required number of lines from an output of a command which is in tabular form. Below is the command for reference along with how the result is being shown on UNIX shell. /usr/openv/volmgr/bin/vmquery -b -p 5 The result of the above command is as... (6 Replies)
Discussion started by: Ali Sarwar
6 Replies

2. Shell Programming and Scripting

Grep command output in tabular format

I have a grep command script which works fine and give the correct results but i wanted the output to be displayed in tabular format ? Is it possible to display the output in tabular format and as well direct them to some file. main script : #!/usr/bin/bash Start_Time=`date '+%m%d%y... (1 Reply)
Discussion started by: Optimus81
1 Replies

3. Shell Programming and Scripting

Displaying log file pattern output in tabular form output

Hi All, I have result log file which looks like this (below): from the content need to consolidate the result and put it in tabular form 1). Intercomponents Checking Passed: All Server are passed. ====================================================================== 2). OS version Checking... (9 Replies)
Discussion started by: Optimus81
9 Replies

4. Shell Programming and Scripting

Mail attachment dispaying in different format.

Hi friends, I have file1.txt where i am sending this file as attatment in mail using below code uuencode file1.txt file1.txt | mail -s 'TestFile' test@test.com but the format of the file is changing when i open in attachement. file1.txt in unix 1|hyd|nag 2|jun|kin ... (4 Replies)
Discussion started by: i150371485
4 Replies

5. Shell Programming and Scripting

Displaying output in the tabular format

Hi I want to display the following input data into the tabular format as shown in the output. Input.txt: Following jobs are in pending state for more than 10 minutes: JOB_ID JOB_SUBMIT_ID MAHAR 784308 PUNJA 109367 Following jobs are running for longer time: JOB_ID... (1 Reply)
Discussion started by: dats
1 Replies

6. UNIX for Dummies Questions & Answers

Put data in tabular form..

Dear Friends, I have a file as under : +++ ME 12-06-13 18:16:20 A RED FEW AND ROW1 1MN FEL AS HI FI BV LR TS HR ES MR * 0 13296 0 120 1 15 KS RR 10 0 +++ ME 12-06-13 18:26:20 A RED FEW AND ROW2 1MN FEL AS... (2 Replies)
Discussion started by: vanand420
2 Replies

7. UNIX for Dummies Questions & Answers

Put data into tabular form

Hi I am having a file which is required to be presented in the under-noted output form. Please suggest. Input: Kapil: apple 4 banana 6 cherry 0 Manoj: apple 13 banana cheery 2 Output: apple banana cherry Kapil: 4 6 0 Manoj: 13 2 Thanks in... (4 Replies)
Discussion started by: vanand420
4 Replies

8. Shell Programming and Scripting

Tabular form in shell script

hi, I need to mention the data in tabular form in shell script. :confused: Input as below: Health check (heading1) CPU/Memory Utilization of pc on server (h2) 1214 of rpc3 is exceeds 0.3 % (data) CPU Utilization is normal for rpc/33 on 2673 CPU Utilization is normal for rpc/33 on... (2 Replies)
Discussion started by: sreelu
2 Replies

9. Shell Programming and Scripting

generate tabular output from an input text file in unix shell scripting

Hi, I have the output (as below) which i want it to be in a table. For e.g. space utilization in PSE on path /logs is 0% space utilization in PSE on path /logs/tuxedo/tuxlsp is 16% space utilization in PSE on path /ldvarlsp/lsp/log is 37% space utilization in PSE on path /home is 6%... (7 Replies)
Discussion started by: pkbond
7 Replies

10. Shell Programming and Scripting

Displaying the output in the tabular Format

Hi, I have a file which contains the data in the below format and need to develop a script which will give the output in the tabular format. Could you please advice me. Folder: Workflow: version . Workflow run status: Workflow run error code: Schedule time: Workflow run type: ... (2 Replies)
Discussion started by: kandi.reddy
2 Replies

Featured Tech Videos