The UNIX and Linux Forums  

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


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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Formatting Output dhanamurthy Shell Programming and Scripting 6 05-02-2008 08:43 AM
Formatting bdf output Cameron Shell Programming and Scripting 5 04-09-2008 06:05 AM
formatting output balaji_prk Shell Programming and Scripting 4 09-15-2007 06:23 AM
Formatting output illur81 Shell Programming and Scripting 3 10-13-2005 06:24 AM
Formatting the output Cameron Shell Programming and Scripting 7 02-15-2002 07:30 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-17-2008
Registered User
 

Join Date: Jan 2008
Posts: 5
help on formatting output (Table Form)

Data in File

ABCEFGHI:123
ABCZYEEFI:123
ABCFGDEF:123
ABCEERRRRREFGHI:123

Expected Format

1 ABC DEFGHIFE 123
2 ABCZYE DEFI 123
3 ABCFGD DEF 123
4 ABCEERRRRR DEFGHI 123

However when i enter the following command:

awk 'BEGIN {FS=":"}{printf("%u %s\t%s\t%s\n", NR, $1, $2, $3)} END {print "End List"}' data.txt

Actual Output

1 ABC DEFGHIFE 123
2 ABCZYE DEFI 123
3 ABCFGD DEF 123
4 ABCEERRRRR DEFGHI 123

how can i set the width of each column?
Reply With Quote
Forum Sponsor
  #2  
Old 01-17-2008
Resident BOFH
 

Join Date: Dec 2007
Posts: 262
get rid of the tabs and use the field width within printf. check the man page for details.

ie:

Code:
printf "%20s\n" blah

Code:
     Field Width:
             An optional digit string specifying a field width; if the output
             string has fewer characters than the field width it will be blank-
             padded on the left (or right, if the left-adjustment indicator has
             been given) to make up the field width (note that a leading zero is
             a flag, but an embedded zero is part of a field width);


also - please use the code tags around your code/data. That way we do not see smiley
faces in the middle of your data.
Reply With Quote
  #3  
Old 01-18-2008
Registered User
 

Join Date: Jan 2008
Posts: 5
thank you very much.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0