![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
Be more specific. Provide what your desired output should look like
|
|
#4
|
|||
|
|||
|
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
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 |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
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
|
|
#7
|
|||
|
|||
|
earlepps - don't post in two places.
You got basically the same answer - twice - and wasted tmarikle's time. |
|||
| Google The UNIX and Linux Forums |