Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

formatting tab with even size

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-19-2010
ivpz ivpz is offline
Registered User
 
Join Date: Dec 2009
Last Activity: 1 September 2014, 1:07 PM EDT
Posts: 28
Thanks: 1
Thanked 0 Times in 0 Posts
formatting tab with even size

I have a number of columns separated by tabs but the spacing between them are of different sizes. Is there any way of separating them with tab of even size?

Thank you.
Sponsored Links
    #2  
Old Unix and Linux 01-19-2010
clx clx is offline Forum Advisor  
Registered User
 
Join Date: Jun 2007
Last Activity: 22 April 2015, 7:02 AM EDT
Location: Mumbai, India
Posts: 1,665
Thanks: 130
Thanked 196 Times in 190 Posts
you can format the output with printf.


Code:
echo 'x y' | awk '{printf "%s%16s\n", $1, $2}'
x               y

Sponsored Links
    #3  
Old Unix and Linux 01-19-2010
ivpz ivpz is offline
Registered User
 
Join Date: Dec 2009
Last Activity: 1 September 2014, 1:07 PM EDT
Posts: 28
Thanks: 1
Thanked 0 Times in 0 Posts
Sorry for asking something which may be obvious but what do %s and %16s mean?
Thank you.
    #4  
Old Unix and Linux 01-19-2010
clx clx is offline Forum Advisor  
Registered User
 
Join Date: Jun 2007
Last Activity: 22 April 2015, 7:02 AM EDT
Location: Mumbai, India
Posts: 1,665
Thanks: 130
Thanked 196 Times in 190 Posts
those are formatting specifiers of printf.
google printf for more information.
%s is for string. %16s means prints the $2 as a string of 16 characters (right justified).
Sponsored Links
    #5  
Old Unix and Linux 01-19-2010
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 26 April 2015, 11:08 AM EDT
Location: The Netherlands
Posts: 7,730
Thanks: 128
Thanked 544 Times in 512 Posts
Have a read of Using printf Statements for Fancier Printing.
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Directory size larger than file system size? sparcman Solaris 6 12-10-2009 09:21 AM
find with file size and show the size rpraharaj84 Shell Programming and Scripting 3 10-06-2009 01:42 PM
Formatting mirusnet Shell Programming and Scripting 3 01-06-2008 10:38 PM
command to find out total size of a specific file size (spread over the server) abhinov Solaris 3 08-08-2007 06:48 AM
bash script working for small size files but not for big size files. davidpreml Shell Programming and Scripting 1 11-01-2006 10:06 AM



All times are GMT -4. The time now is 03:25 PM.