output spacing and formatting


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers output spacing and formatting
# 1  
Old 10-02-2012
output spacing and formatting

here is my code and output, i just want to display it clearly to the users. how can I fix the spacing or put some headers like NAME, DEV id, Size, Meta

code:
Code:
symdg show $INS-${SNAP} | egrep "D-" | awk '{print $1,$3,$NF,$5}'

output:
Code:
D-arch 23C2 983040 (M)
D-db 0704 245760 (M)
D-undo 07DB 983040 (M)
D-temp 07E3 983040 (M)
D-index1 07EB 1966080 (M)
D-index2 07FB 1966080 (M)
D-index3 080B 1966080 (M)
D-data1 081B 1966080 (M)
D-data2 082B 1966080 (M)
D-data3 083B 1966080 (M)
D-data4 084B 1966080 (M)
D-data5 085B 1966080 (M)
D-data6 086B 1966080 (M)
D-data7 087B 1966080 (M)
D-redoa 0694 61440 (M)
D-redob 06A4 61440 (M)
D-cm 2306 737280 (M)
D-redoc 22F6 30720 (M)
D-redod 22FE 30720 (M)
D-rat 5CF9 491520 (M)
D-redoraw01a 5E51 30720 (M)
D-redoraw02a 5E59 30720 (M)
D-redoraw03a 5E61 30720 (M)
D-redoraw04a 5E69 30720 (M)
D-redoraw05a 5E71 30720 (M)
D-redoraw06a 5E79 30720 (M)
D-redoraw07a 5E81 30720 (M)
D-redoraw08a 5E89 30720 (M)


also, how do i tell awk to capture null values? because when i ask it to print $5 and if it has a null value there, it prints column 6 instead so its a bit inconsistent. thanks a lot in advance.

Last edited by Scrutinizer; 10-02-2012 at 06:06 AM.. Reason: code tags
# 2  
Old 10-02-2012
Quote:
Originally Posted by prodigy06
here is my code and output, i just want to display it clearly to the users. how can I fix the spacing or put some headers like NAME, DEV id, Size, Meta
code:
Code:
symdg show $INS-${SNAP} | egrep "D-" | awk '{print $1,$3,$NF,$5}'

Modify your awk command:
Code:
awk 'BEGIN {print "NAME         DEV id Size    Meta"}{printf "%12s %5s %7s %3s\n",$1,$3,$NF,$5}'

Quote:
also, how do i tell awk to capture null values? because when i ask it to print $5 and if it has a null value there, it prints column 6 instead so its a bit inconsistent. thanks a lot in advance.
What do you mean by NULL values? There should be two adjacent separator chars, so generally awk can tell $5 from $6. Pls. provide an input example.

Last edited by RudiC; 10-02-2012 at 11:32 AM.. Reason: made print -> printf
# 3  
Old 10-02-2012
Try this awk statement:

Code:
awk '{gsub(" ",":");c=split($0,a,":");print a[1],a[3],a[c],a[5]}'

# 4  
Old 10-02-2012
@rudic: this is what it gave me
code:
Code:
symdg show $INS-${SNAP} | egrep "D-" | awk 'BEGIN {print "NAME         DEV id Size    Meta"}{print "%12s %5s %7s %3s\n",$1,$3,$NF,$5}'

output:
Code:
NAME         DEV id Size    Meta
%12s %5s %7s %3s
 D-data1 2DB3 60338 RW
%12s %5s %7s %3s
 D-data2 2DB4 60338 RW
%12s %5s %7s %3s
 D-data3 2DB5 60338 RW
%12s %5s %7s %3s
 D-data4 2DB6 60338 RW
%12s %5s %7s %3s
 D-data5 02ED 60338 RW
%12s %5s %7s %3s
 D-data6 0E86 60338 RW
%12s %5s %7s %3s
 D-index1 2DB7 60338 RW
%12s %5s %7s %3s
 D-index2 2DB8 60338 RW
%12s %5s %7s %3s
 D-index3 0E87 60338 RW
%12s %5s %7s %3s
 D-undo 2DB9 60338 RW
%12s %5s %7s %3s
 D-arch 2DBB 60338 RW
%12s %5s %7s %3s
 D-redoa 2127 10260 Mir
%12s %5s %7s %3s
 D-redob 2128 10260 Mir
%12s %5s %7s %3s
 D-db 10AE 17428 RW
%12s %5s %7s %3s
 D-data7 03C1 120675 (M)
%12s %5s %7s %3s
 D-index4 34BD 60338 RW

@rdrtx1: it gave me

Code:
awk: syntax error near line 1
awk: illegal statement near line 1

---------- Post updated at 08:37 PM ---------- Previous update was at 08:35 PM ----------

@rudic: this is the output im grepping, and column 5 has no value on some so it jumps on the next one (RW) column when i print $5.

Code:
       ----------------------------------------------------------------------------------
                                                      Sym  Device                     Cap
        LdevName              PdevName                Dev  Config        Att. Sts     (MB)
        ----------------------------------------------------------------------------------
        D-data1               N/A                     2DB3 RAID-5             RW     60338
        D-data2               N/A                     2DB4 RAID-5             RW     60338
        D-data3               N/A                     2DB5 RAID-5             RW     60338
        D-data4               N/A                     2DB6 RAID-5             RW     60338
        D-data5               N/A                     02ED RAID-5             RW     60338
        D-data6               N/A                     0E86 RAID-5             RW     60338
        D-index1              N/A                     2DB7 RAID-5             RW     60338
        D-index2              N/A                     2DB8 RAID-5             RW     60338
        D-index3              N/A                     0E87 RAID-5             RW     60338
        D-undo                N/A                     2DB9 RAID-5             RW     60338
        D-arch                N/A                     2DBB RAID-5             RW     60338
        D-redoa               N/A                     2127 2-Way Mir          RW     10260
        D-redob               N/A                     2128 2-Way Mir          RW     10260
        D-db                  N/A                     10AE RAID-5             RW     17428
        D-data7               N/A                     03C1 RAID-5        (M)  RW    120675
        D-index4              N/A                     34BD RAID-5             RW     60338


Last edited by Scrutinizer; 10-02-2012 at 11:24 AM.. Reason: code tags
# 5  
Old 10-02-2012
Sorry, typo - use printf instead of the second print.

And regarding your grep result: lines 12, 13, and 15 have a space in what you would call "col 4", e.g. "2-way Mir", so awk separates this into $4 and $5, totalling to 7 fields instead of 6. Can you create the file with a different field separator, e.g. comma or <TAB>?

Last edited by RudiC; 10-02-2012 at 10:17 AM..
# 6  
Old 10-02-2012
column 5 is the Attribute tab where it displays "(M)" which is in line 15:

Code:
D-data7               N/A                     03C1 RAID-5        (M)  RW    120675

and this is my current output, (spacing and format is ok now thanks), as you can see there is RW and Mir there, which should not be there.

NAME           DEV id    Size    Meta
D-data1        2DB3     60338      RW
D-data2        2DB4     60338      RW
D-data3        2DB5     60338      RW
D-data4        2DB6     60338      RW
D-data5        02ED     60338      RW
D-data6        0E86     60338      RW
D-index1       2DB7     60338      RW
D-index2       2DB8     60338      RW
D-index3       0E87     60338      RW
D-undo         2DB9     60338      RW
D-arch         2DBB     60338      RW
D-redoa        2127     10260     Mir
D-redob        2128     10260     Mir
D-db           10AE     17428      RW
D-data7        03C1     120675    (M)
D-index4       34BD     60338      RW


Last edited by Scrutinizer; 10-02-2012 at 11:23 AM.. Reason: code tags
# 7  
Old 10-02-2012
You need to use code tags to preserve formatting in code and data.

Regards,
Alister
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Formatting the Output

Hi, I am trying to use printf command and format certain output in a specific format as under: While the left side (upto |) of the above format is part of a fixed header function, the right side is where i am expecting data to be printed. However, as seen, Row1 value is reflecting on last... (5 Replies)
Discussion started by: EmbedUX
5 Replies

2. Shell Programming and Scripting

Formatting output

I have the output like below: DEV#: 9 DEVICE NAME: hdisk9 TYPE: 1750500 ALGORITHM: Load Balance SERIAL: 68173531021 ========================================================================== Path# Adapter/Path Name State Mode Select Errors 0 ... (4 Replies)
Discussion started by: Daniel Gate
4 Replies

3. Shell Programming and Scripting

Preserving file format and spacing in output file

Hi I have a file with the following structure "VATTENFALL GLOBAL" "Vattenfall Tray" "BARCLAYS BANK LONDON" "Capula" "P1 AGEAS GLOBAL COMPANY" "AAC - Optiver" The requirement is like this 1) Take 2 input... (16 Replies)
Discussion started by: sudeep.id
16 Replies

4. Shell Programming and Scripting

Output formatting .

below is a CPU utilization Log for ABC server. However for every 15 minutes it generates 3 CPU values(with interval of 2 sec). Host CPU CPUtotal CPU% time ABC 101.1 2 50.55 14 : 15 ABC 100.5 2 50.25 14 : 15 ABC 100.2 2 50.1 14 : 15 ABC 100.9 2 50.45 14 : 30 ABC 100.5 2 50.25 14 : 30 ABC... (5 Replies)
Discussion started by: pinga123
5 Replies

5. Shell Programming and Scripting

Formatting of output

Hi Experts, I have to create a report for certain audit and my output looks as follows I m trying to format my output to look like Any inputs would be highly appreciated Thanks Syed (5 Replies)
Discussion started by: maverick_here
5 Replies

6. Shell Programming and Scripting

Output formatting

I have input file in this way John 1234 BASIC 26000 John 1234 ALLOWC 01550 John 1234 INCER 01700 John 1234 REL 20000 Debi 2345 BASIC 29000 Debi 2345 ALLOWC 01600 Debi 2345 INCR 01900 Debi 2345 REL ... (8 Replies)
Discussion started by: vakharia Mahesh
8 Replies

7. Shell Programming and Scripting

Formatting my output

Dear All, I am new to unix scripting. I need your help to format my output on screen. echo " --------------------------------------------" echo " | My Output |" echo " --------------------------------------------" echo " | A: $A... (5 Replies)
Discussion started by: rahiljavaid
5 Replies

8. Shell Programming and Scripting

Formatting ls output

I am using find and ls to search for "warez" files on my server. find /home/ -regex ".*\.\(avi\|mp3\|mpeg\|mpg\|iso\)" -print0 | xargs -0 ls -oh This command produces this: -rw-r--r-- 1 1000 3.2M Feb 18 2009 /home/user/public_html/lupus.mp3 I want to only get this 3.2M... (4 Replies)
Discussion started by: bonrad
4 Replies

9. Shell Programming and Scripting

formatting the output

Is it possible to convert the attached file to the format mentioned. Here for a particular job the table name and the corresponding instance name from one test run "X" is compared with the table name and the instance name from the second test run "Y" for output rows,affected rows,applied... (1 Reply)
Discussion started by: ragavhere
1 Replies

10. Shell Programming and Scripting

formatting output

Hi need some advice.. #grep -i hostname test.csv (gives the below output) HOSTNAME,name,host_test,,,,,,,, Now I need to format the above output as below. HOSTNAME: name=host_test Any easy way of doing this using awk or sed or printf? (4 Replies)
Discussion started by: balaji_prk
4 Replies
Login or Register to Ask a Question