The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
c program to extract text between two delimiters from some text file kukretiabhi13 High Level Programming 7 1 Day Ago 03:29 PM
align several fields and fill spaces with zero DebianJ Shell Programming and Scripting 2 11-23-2005 04:51 AM
how to align report headers in awk galinaqt Shell Programming and Scripting 3 10-16-2005 12:41 PM
How to underline/bold and how to align output clara UNIX for Dummies Questions & Answers 1 06-16-2005 09:41 AM
grep multiple text files in folder into 1 text file? coppertone UNIX for Dummies Questions & Answers 7 08-23-2002 11:50 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-31-2006
Registered User
 

Join Date: Jul 2006
Posts: 5
Question Align Text from a file.

I need to align text from a file that has columns seperated by spaces and commas. Any ideas?

Text is similar to this.

File Name is Test.

05/14/06 13:46:56.575 ,TEST,5,123,1234,123,12345,12,12.2,2.1,4.5,5.23
05/14/06 13:49:58.009 ,TEST,6,456,456.7,45,4.56,453,34,54.3,3.2,6.456
Reply With Quote
Forum Sponsor
  #2  
Old 07-31-2006
Registered User
 

Join Date: Jul 2006
Posts: 5
Question Align Text from a file.

I need to align text from a file that has columns seperated by spaces and commas. Any ideas?

Text is similar to this.

File Name is Test.

05/14/06 13:46:56.575 ,TEST,5,123,1234,123,12345,12,12.2,2.1,4.5,5.23
05/14/06 13:49:58.009 ,TEST,6,456,456.7,45,4.56,453,34,54.3,3.2,6.456
Reply With Quote
  #3  
Old 07-31-2006
Registered User
 

Join Date: Jan 2005
Posts: 682
Be more specific. Provide what your desired output should look like
Reply With Quote
  #4  
Old 07-31-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
Code:
#!/bin/ksh

tr -s ' ' ',' < test  > tmpfile
awk -F, ' \
     {
	   printf("%8s %12s %4s ", $1, $2, $3)
           for(i=4;i<=NF;i++)
           {
           	 printf("%10.3f ",$i)
           }
           printf("\n")
     } ' tmpfile
output:
Code:
05/14/06 13:46:56.575 TEST      5.000    123.000   1234.000    123.000  12345.000     12.000     12.200      2.100      4.500      5.230
05/14/06 13:49:58.009 TEST      6.000    456.000    456.700     45.000      4.560    453.000     34.000     54.300      3.200      6.456
Reply With Quote
  #5  
Old 07-31-2006
Registered User
 

Join Date: Jul 2006
Posts: 5
Arrow

Here is the desire output

05/14/06 13:46:56.575 TEST 5 123 1234 123 12345 12 12.2 2.1 4.5 5.23
05/14/06 13:49:58.009 TEST 6 456 456.7 45 4.56 453 34 54.3 3.2 6.456


Doesn't look right in this Forum Field.

Basically

##### ###### ### #### ### #### #### #####
##### ###### ### #### ### #### #### #####

Last edited by earlepps; 07-31-2006 at 11:53 AM.
Reply With Quote
  #6  
Old 07-31-2006
Registered User
 

Join Date: Jan 2005
Posts: 682
awk can be used for this:

Code:
print "05/14/06 13:46:56.575 ,TEST,5,123,1234,123,12345,12,12.2,2.1,4.5,5.23
05/14/06 13:49:58.009 ,TEST,6,456,456.7,45,4.56,453,34,54.3,3.2,6.456" |
nawk -F, '
    { printf ("%-20s %-10s %-3d %12.2f %12.2f %12.2f %12.2f %12.2f %12.2f %12.2f %12.2f %12.2f \n", $1, $2, $3, $4, $5, $6 $7, $8, $9, $10, $11, $12, $13, $14) }
'
05/14/06 13:46:56.575  TEST       5         123.00      1234.00  12312345.00        12.00        12.20         2.10         4.50         5.23         0.00 
05/14/06 13:49:58.009  TEST       6         456.00       456.70       454.56       453.00        34.00        54.30         3.20         6.46         0.00
This should help you some.
Reply With Quote
  #7  
Old 07-31-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
earlepps - don't post in two places.
You got basically the same answer - twice - and wasted tmarikle's time.
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 12:06 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