formatting tab with even size | 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.

formatting tab with even size

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-19-2010
ivpz ivpz is offline
Registered User
 
Join Date: Dec 2009
Last Activity: 18 July 2014, 2:05 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 01-19-2010
clx clx is offline Forum Advisor  
Registered User
 
Join Date: Jun 2007
Last Activity: 30 July 2014, 4:26 AM EDT
Location: Mumbai, India
Posts: 1,611
Thanks: 124
Thanked 182 Times in 176 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
ivpz ivpz is offline
Registered User
 
Join Date: Dec 2009
Last Activity: 18 July 2014, 2:05 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 01-19-2010
clx clx is offline Forum Advisor  
Registered User
 
Join Date: Jun 2007
Last Activity: 30 July 2014, 4:26 AM EDT
Location: Mumbai, India
Posts: 1,611
Thanks: 124
Thanked 182 Times in 176 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
Franklin52's Avatar
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 30 July 2014, 3:46 AM EDT
Location: The Netherlands
Posts: 7,692
Thanks: 120
Thanked 531 Times in 502 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 11:09 AM.