Arranging Haphazard output in readable format | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Arranging Haphazard output in readable format

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-18-2013
anushree.a anushree.a is offline
Registered User
 
Join Date: May 2008
Last Activity: 22 January 2013, 5:56 AM EST
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Arranging Haphazard output in readable format

Dear Friends,
Need your help once again.

I have a sql to download output in pipe separated format.
Due to that output looks haphazard.

E.G.


Code:
$cat output.temp

123|456|789|0
67345123||3455|1
7124563|432343414||345324

By any was can we arrange it in tabular format for better readability?

Please guide me.

Thanks
Anu.

Last edited by Scott; 01-18-2013 at 04:15 AM.. Reason: Code tags
Sponsored Links
    #2  
Old 01-18-2013
balajesuri's Avatar
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 20 August 2014, 12:23 PM EDT
Location: India
Posts: 1,822
Thanks: 24
Thanked 523 Times in 502 Posts

Code:
awk -F'|' '{for (i=1;i<=NF;i++){printf "%-20s", $i}}{printf "\n"}' file

Sponsored Links
    #3  
Old 01-18-2013
Visshal Visshal is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 18 January 2013, 4:20 AM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
one way is you can run your sql query to get the output in csv format. Or you can run a script on this output replace | with , and open the file in excel or any spreadsheet. That way you can see output in tabular format.

Or just try following and open the file into spreadsheet.


Code:
me@lappy:~/Documents/file$ cat tmp.txt
123|456|789|0
67345123|3455|1
7124563|432343414|345324
me@lappy:~/Documents/file$ sed -e s/\|/,/g tmp.txt 
123,456,789,0
67345123,3455,1
7124563,432343414,345324

    #4  
Old 01-18-2013
cero cero is offline
Registered User
 
Join Date: Aug 2006
Last Activity: 20 August 2014, 9:09 AM EDT
Posts: 363
Thanks: 3
Thanked 64 Times in 59 Posts
Look if you have the column utility available on your system.

Code:
$ cat output.temp
123|456|789|0
67345123||3455|1
7124563|432343414||345324
$ column -nt -s'|' output.temp
123       456        789   0
67345123             3455  1
7124563   432343414        345324

Edit: the -n option is a Debian GNU/Linux extension, so maybe not available to you - your manpage will tell.
Sponsored Links
    #5  
Old 01-18-2013
drl's Avatar
drl drl is offline Forum Advisor  
Registered Voter
 
Join Date: Apr 2007
Last Activity: 20 August 2014, 10:59 AM EDT
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 1,665
Thanks: 37
Thanked 188 Times in 172 Posts
Hi.

Using the perl utility align on the data in file data1:

Code:
% align -s '/\|' -ar -j_ -g3 data1
     123         456    789        0
67345123               3455        1
 7124563   432343414          345324

One can select the field separation pattern as "|', the alignment is right, the output separation is done with space characters, and the gutter is 3 spaces, so that numbers can be easily compared. There are generally appropriate defaults for these, but you can change them if desired, as illustrated

See the page for details and download: align ? Freecode

Best wishes .. cheers, drl
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need Help in arranging the output Sudeep Bhattad Shell Programming and Scripting 4 10-25-2012 03:21 AM
help in extracting logs in readable format eanne_may UNIX for Dummies Questions & Answers 1 08-29-2011 12:24 PM
vmstat in a better readable format tom_k_mishra UNIX for Dummies Questions & Answers 1 03-29-2010 03:01 AM
file in malibox is readable format? megh HP-UX 1 08-13-2008 01:13 PM
To convert multi format file to a readable ascii format gaur.deepti UNIX for Dummies Questions & Answers 5 03-25-2008 03:03 PM



All times are GMT -4. The time now is 12:20 AM.