Left Align of Text File


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Left Align of Text File
# 1  
Old 08-07-2012
MySQL Left Align of Text File

Input:

Code:
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 98.5 n 1.05 2.50 -550 -110 1:25:200
delhi 98.61 y 1.05 2.50 -550 -110 1:25:200
hyderabad 99.02 y 1.05 2.50 -550 -110 1:25:200
..
..

Output:

Code:
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     98.5    n  1.05  2.50  -550  -110  1:25:200
delhi          98.61   y  1.05  2.50  -550  -110  1:25:200
hyderabad      99.02   y  1.05  2.50  -550  -110  1:25:200
...

Just I want my output as left align so it's looks good.

Thanks
# 2  
Old 08-07-2012
Code:
while read LINE
do
        printf "%10s" $LINE
done < input > output

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 08-07-2012
Using the above file sample and code i get:
Code:
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
      98.5
         n
      1.05
      2.50
      -550
      -110
  1:25:200
     delhi
     98.61
         y
      1.05
      2.50
      -550
      -110
  1:25:200
 hyderabad
     99.02
         y
      1.05
      2.50
      -550
      -110
  1:25:200

awk '{printf("%15s %10.3f %10s %10s %10s %10s %10s\n", $1,$2,$3,$4,$5,$6,$7)}' filename > newfilename

Code:
seems to work.

This User Gave Thanks to jim mcnamara For This Post:
# 4  
Old 08-07-2012
Quote:
Originally Posted by jim mcnamara
Using the above file sample and code i get:
Code:
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
      98.5
         n
      1.05
      2.50
      -550
      -110
  1:25:200
     delhi
     98.61
         y
      1.05
      2.50
      -550
      -110
  1:25:200
 hyderabad
     99.02
         y
      1.05
      2.50
      -550
      -110
  1:25:200

Then you made a typo somewhere. My code has a bug, but it's the lack of newlines, not extra ones...

Code:
while read LINE; do         printf "%10s" $LINE; echo; done < datafile
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      98.5         n      1.05      2.50      -550      -110  1:25:200
     delhi     98.61         y      1.05      2.50      -550      -110  1:25:200
 hyderabad     99.02         y      1.05      2.50      -550      -110  1:25:200

$

Adjust the width(10) to taste.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 08-08-2012
Have you tried:
Code:
echo "hiddenhausen  99.60   y  1.05  2.50  -550  -110  1:25:200..." | column -t

These 2 Users Gave Thanks to leafei For This Post:
# 6  
Old 08-08-2012
Quote:
Originally Posted by asavaliya
Input:

Code:
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 98.5 n 1.05 2.50 -550 -110 1:25:200
delhi 98.61 y 1.05 2.50 -550 -110 1:25:200
hyderabad 99.02 y 1.05 2.50 -550 -110 1:25:200
..
..

... <snip> ...

Just I want my output as left align so it's looks good.
Corona's while-read loop with the following printf statement will left-align those 8 fields:
Code:
printf '%-12s %-8s %-1s %-8s %-8s %-8s %-8s %-12s\n' $LINE

Adjust the field widths as you see fit.

Regards,
Alister

---------- Post updated at 09:13 AM ---------- Previous update was at 09:09 AM ----------

Quote:
Originally Posted by leafei
Have you tried:
Code:
echo "hiddenhausen  99.60   y  1.05  2.50  -550  -110  1:25:200..." | column -t

Not all systems will have that command, but if it is available, it's a nice solution since it can just read the file (or stdin) directly.

Regards,
Alister
This User Gave Thanks to alister For This Post:
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

Ftp with bash, append file where left off

I'm working on a bash script to finish uploading a file. I need a way to get $filesize so that "restart $filesize" will work. Here is my script: ftp -n -v <<END_SCRIPT open ftp.$domain user $user@$domain $password size $file restart $filesize put $file quit END_SCRIPTWayne Sallee... (9 Replies)
Discussion started by: WayneSallee
9 Replies

4. 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

5. Solaris

File system full - not removed: No space left on device

Does anyone have any advise on trying to clean up a full filesystem? I can't rm any files because of the follow: not removed: No space left on device Any help would be very much appreciated. (10 Replies)
Discussion started by: craigsky
10 Replies

6. Shell Programming and Scripting

File count from where it left??

i have this code num=1 dat10=`date "+%m/%d/%Y" -d "+10 days"` dat=`date "+%m/%d/%Y"` set -x grep "text=.&" /root/Softwares/apache-tomcat-5.5.30/logs/catalina.out|awk -F"from=" '{print $2}'|awk -F"opid" '{print $1}'|sort|uniq > pnos while read line do psql -U poss -d emsver -c "insert into... (3 Replies)
Discussion started by: nikhil jain
3 Replies

7. 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

8. Shell Programming and Scripting

Howto process log file from where it left

Hi all I am doing some matching apache access log processing.Now i want a some way that i can start log search/process from where it left.Can any one give me ideads. (1 Reply)
Discussion started by: aliahsan81
1 Replies

9. 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

10. UNIX for Dummies Questions & Answers

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 (9 Replies)
Discussion started by: earlepps
9 Replies
Login or Register to Ask a Question