Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


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

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-19-2010
Registered User
 
Join Date: Dec 2009
Posts: 22
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 01-19-2010
clx clx is offline Forum Advisor  
Registered User
 
Join Date: Jun 2007
Location: Mumbai,India
Posts: 1,417
Thanks: 101
Thanked 133 Times in 129 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 01-19-2010
Registered User
 
Join Date: Dec 2009
Posts: 22
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 01-19-2010
clx clx is offline Forum Advisor  
Registered User
 
Join Date: Jun 2007
Location: Mumbai,India
Posts: 1,417
Thanks: 101
Thanked 133 Times in 129 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 01-19-2010
Moderator
 
Join Date: Feb 2007
Location: The Netherlands
Posts: 7,505
Thanks: 73
Thanked 474 Times in 453 Posts
Have a read of Using printf Statements for Fancier Printing.
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
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 01:27 AM.