How to allign output data in UNIX that is separated with a pipe "|" symbol ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to allign output data in UNIX that is separated with a pipe "|" symbol ?
# 1  
Old 12-14-2012
How to allign output data in UNIX that is separated with a pipe "|" symbol ?

Experts ,
In the given output of the log file, the 2nd field that is separated by "|" pipe is not aligned well due to the uneven data length, I would like it to align the 2nd column with 37 length (that is disturbed in the output) including the pipe . The two pepe "|" would be in a aligned way with length 37 , so it would look better.

Please advise how to align the output ,



Code:
# cat logfile


zmihx88   |     ia64 hp Integrity BL890c i8   |          B.11.23 |         4:84pm  up  99:94,  8  
umihx70   |     ia64 hp server BL870c   |                B.11.23 |         4:84pm  up  98:08,  0 
zmihx79   |     ia64 hp server BL870c   |                B.11.23 |         4:84pm  up  98:09,  0  
zmihx78   |     9000/800/rp8440     |                    B.11.23 |         4:84pm  up   8:76,  0 
zmihx77   |     9000/800/rp8440   |                      B.11.23 |         4:84pm  up  98:86,  0  
wmihx95   |     9000/800/K520   |                        B.11.23 |         4:84pm  up   9:80,  0  
wmihx96   |     9000/800/rp8440   |                      B.11.23 |         4:84pm  up   7:59,  0 
wmihx86   |     9000/800/S96K-A   |                      B.11.31 |         4:84pm  up   4:88,  0  
umihx87   |     9000/800/rp8440     |                    B.11.23 |         4:84pm  up  6:50,   0  
umihx82   |     9000/800/S96K-A   |                      B.11.23 |         4:84pm  up  97:87,  0




The output should be look like below:


Code:
           |<------  37  space --------------->|
		  
zmihx88    |     ia64 hp Integrity BL890c i8   |          B.11.23 |         4:84pm  up  99:94,  8  
umihx70    |     ia64 hp server BL870c         |          B.11.23 |         4:84pm  up  98:08,  0 
zmihx79    |     ia64 hp server BL870c         |          B.11.23 |         4:84pm  up  98:09,  0  
zmihx78    |     9000/800/rp8440               |          B.11.23 |         4:84pm  up   8:76,  0 
zmihx77    |     9000/800/rp8440               |          B.11.23 |         4:84pm  up  98:86,  0  
wmihx95    |     9000/800/K520                 |          B.11.23 |         4:84pm  up   9:80,  0  
wmihx96    |     9000/800/rp8440               |          B.11.23 |         4:84pm  up   7:59,  0 
wmihx86    |     9000/800/S96K-A               |          B.11.31 |         4:84pm  up   4:88,  0  
umihx87    |     9000/800/rp8440               |          B.11.23 |         4:84pm  up  6:50,   0  
umihx82    |     9000/800/S96K-A               |          B.11.23 |         4:84pm  up  97:87,  0



Thanks,
# 2  
Old 12-14-2012
Code:
awk -F\| ' { gsub(" ","",$3); printf "%-10s|%-37s|%10s |%s\n", $1, $2, $3, $4 } ' filename

# 3  
Old 12-14-2012
Small correction to bipinajith's code for getting desired result.. Smilie

Code:
awk -F\| ' { gsub(" ","",$3); printf "%-10s|%-37s|%15s |%s\n", $1, $2, $3, $4 } ' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk :help to parse a file to change to separated by colon ":"

Hi experts , I am trying to get the below output: file : 0/6/4/1 0x0019503C2E26 5 UP lan5 snap5 1 ETHER Yes 224 0/6/4/0 0x0019503C2E25 6 UP lan6 snap6 2 ETHER Yes 224 0/2/1/0 0x0019503E6900 0 UP lan0 snap0 3 ETHER Yes 224... (8 Replies)
Discussion started by: rveri
8 Replies

2. Shell Programming and Scripting

How to sort a column in UNIX that is colon separated ":" ?

Experts, how to sort this fields with numerical order : -How to use the sort command in this case, I was thinking with -k but it is not working, lan5000 lan5000:1 lan5000:10 lan5000:11 lan5000:12 lan5000:13 lan5000:14 lan5000:15 lan5000:16 lan5000:17 ... (6 Replies)
Discussion started by: rveri
6 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. Shell Programming and Scripting

"Join" or "Merge" more than 2 files into single output based on common key (column)

Hi All, I have working (Perl) code to combine 2 input files into a single output file using the join function that works to a point, but has the following limitations: 1. I am restrained to 2 input files only. 2. Only the "matched" fields are written out to the "matched" output file and... (1 Reply)
Discussion started by: Katabatic
1 Replies

5. UNIX for Dummies Questions & Answers

Explanation of "total" field in "ls -l" command output

When I do a listing in one particular directory (ls -al) I get: total 43456 drwxrwxrwx 2 root root 4096 drwxrwxrwx 3 root root 4096 -rwxrwxr-x 1 nobody nobody 3701594 -rwxrwxr-x 1 nobody nobody 3108510 -rwxrwxr-x 1 nobody nobody 3070580 -rwxrwxr-x 1 nobody nobody 3099733 -rwxrwxr-x 1... (1 Reply)
Discussion started by: proactiveaditya
1 Replies

6. Shell Programming and Scripting

How to cut a line with the delimeter "pipe symbol"

Hi I am unable to cut a line with the delimeter as a pipe symbol "|" COuld you please help me ? below is the code i am using right now ************ for i in `cat xyz` do source=`echo $i | cut -f 1 -d |` echo $source done ********* Error i am recieving while exceuting the above... (7 Replies)
Discussion started by: Tasha_T
7 Replies

7. Shell Programming and Scripting

How to cut a file using " ", but fields can be separated with more than one " "

Hello, let's say I have a text file: word11 word12 word13 word21 word22 word23 word31 word32 word33 and I want to put the second field of each line into a list: set list = `cut -d" " -f2 ${1}` and I use space (" ") as a delimiter, only that there's a catch: there can be more than... (12 Replies)
Discussion started by: shira
12 Replies

8. UNIX for Dummies Questions & Answers

Encoding Problem while using "|" (PIPE) as delimiter from Mainframe to Unix

We are facing a problem with PIPE (|) as a delimiter in one of our FTP flat files. We are constructing a Flat file in IBM-AIX and this contains various strings delimted by PIPE Symbol and then FTPing this to a Mainframe System The Mainframe program simply recieves this and FTPs the same... (1 Reply)
Discussion started by: seshendra
1 Replies

9. Debian

Debian: doubt in "top" %CPU and "sar" output

Hi All, I am running my application on a dual cpu debian linux 3.0 (2.4.19 kernel). For my application: <sar -U ALL> CPU %user %nice %system %idle ... 10:58:04 0 153.10 0.00 38.76 0.00 10:58:04 1 3.88 0.00 4.26 ... (0 Replies)
Discussion started by: jaduks
0 Replies

10. UNIX for Advanced & Expert Users

Commands on Digital Unix equivalent to for "top" and "sar" on other Unix flavour

Hi, We have a DEC Alpha 4100 Server with OSF1 Digital Unix 4.0. Can any one tell me, if there are any commands on this Unix which are equivalent to "top" and "sar" on HP-UX or Sun Solaris ? I am particularly interested in knowing the CPU Load, what process is running on which CPU, etc. ... (1 Reply)
Discussion started by: sameerdes
1 Replies
Login or Register to Ask a Question