Align Text from a file.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Align Text from a file.
# 1  
Old 07-31-2006
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
# 2  
Old 07-31-2006
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
# 3  
Old 07-31-2006
Be more specific. Provide what your desired output should look like
# 4  
Old 07-31-2006
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

# 5  
Old 07-31-2006
CPU & Memory

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 03:53 PM..
# 6  
Old 07-31-2006
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.
# 7  
Old 07-31-2006
earlepps - don't post in two places.
You got basically the same answer - twice - and wasted tmarikle's time.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. UNIX for Beginners Questions & Answers

How to align/sort the column pairs of an csv file, based on keyword word specified in another file?

I have a csv file as shown below, xop_thy 80 avr_njk 50 str_nyu 60 avr_irt 70 str_nhj 60 avr_ngt 50 str_tgt 80 xop_nmg 50 xop_nth 40 cyv_gty 40 cop_thl 40 vir_tyk 80 vir_plo 20 vir_thk 40 ijk_yuc 70 cop_thy 70 ijk_yuc 80 irt_hgt 80 I need to align/sort the csv file based... (7 Replies)
Discussion started by: dineshkumarsrk
7 Replies

3. Shell Programming and Scripting

Align columns

I have a text file that I filtered using awk. I only exctracted two columns. I want those two columns to be aligned. Most of the answers I found was to use `column -t` command. I tried that but I am getting a `bash: column: command not found`. Is there another way to align columns... (1 Reply)
Discussion started by: erin00
1 Replies

4. Shell Programming and Scripting

Align input fields on one under each other

Hello again, I'm having a issue with a contact form. I want the input fields to be aligned on same row and I really dont know how to do it. I attached a image for you to understand what i am trying to do. <BR> <label for="name" class="required"> Name&nbsp;<strong... (1 Reply)
Discussion started by: galford
1 Replies

5. Shell Programming and Scripting

Align columns

Hi, I have a question on how to align columns in shellscipt. SAMPLE 2015-07-15 09:01:00.0 |TCSERVER01 |10965 2015-07-15 09:02:00.0 |TCSERVER01 |4752 2015-07-15 09:03:00.0 |TCSERVER01 |4805 2015-07-15 09:04:00.0 |TCSERVER01 |3690 2015-07-15 09:01:00.0 |TCSERVER02 |8703 2015-07-15... (1 Reply)
Discussion started by: reignangel2003
1 Replies

6. Shell Programming and Scripting

Align data of the paragraph

Hi, I need your help to align data from paragraph. It's to : - delete the lign contain NDS - align data between paragraph start to "ND=" from second "ND=" example of file: @ ABOIL; @ CEN=1/15-05-23/09 H 06 MN 18/LISTAGE CARACTERISTIQUES D'ABONNES TRAITEMENT TGLAIL ACC... (1 Reply)
Discussion started by: vremen3
1 Replies

7. Shell Programming and Scripting

Left Align of Text File

Input: hiddenhausen 99.60 y 1.05 2.50 -550 -110 1:25:200 herbstein 99.021 n 1.05 2.50 -550 -110 1:25:200 bangalore 98.82 y 1.05 2.50 -550 -110 1:25:200 golm 98.8 y 1.05 2.50 -550 -110 1:25:200 para 98.82 n 1.05 2.50 -550 -110 1:25:200 bogen 98.61 n 1.05 2.50 -550 -110 1:25:200 saintandre... (5 Replies)
Discussion started by: asavaliya
5 Replies

8. Shell Programming and Scripting

Get the ipaddress and align based on the input file

Hi All, I have a file contains below contents, "interfacename/subnet: public (or) interfacename/subnet:cluster_interconnect" "en2"/10.185.81.0:cluster_interconnect,"en5"/10.185.81.0:cluster_interconnect,"en6"/169.181.146.0:public... (6 Replies)
Discussion started by: kamauv234
6 Replies

9. Shell Programming and Scripting

Align the words

HI , I am new to shell scripting i m getting the below format like this Name FirstName Lastname ------ --------- ---------- Name1 Balaji NandaKishore Name123 Vijaya krsihna ... (5 Replies)
Discussion started by: Lucky123
5 Replies

10. Shell Programming and Scripting

Align Text within <p> Tags in a HTML file.

Hi All !!! I have an HTML file whose contents are as below: <html> <body> <title>This is a test file</title> <p>PLEASE ALIGN ME IN ONE LINE. TEXT....</p> <h2>This is a Test file</h2> <p>PLEASE ALIGN ME IN ONE LINE. TEXT....</p> </body> </html> (2 Replies)
Discussion started by: parshant_bvcoe
2 Replies
Login or Register to Ask a Question