The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
string with blank spaces psalas UNIX for Dummies Questions & Answers 4 04-16-2008 04:50 AM
problem with the blank spaces in array kamicasse UNIX for Dummies Questions & Answers 4 12-06-2007 02:40 PM
blank spaces getting deleted gander_ss Shell Programming and Scripting 5 05-15-2007 05:37 AM
remove blank spaces in a string spandu Shell Programming and Scripting 2 03-02-2006 02:08 AM
howtodelete blank spaces forevercalz Shell Programming and Scripting 2 09-29-2005 05:35 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-08-2007
Jae Jae is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 24
Replace blank spaces by single tab, and right alignment

Folks, I am wondering if anyone solve this problem.
What I want to know is,
1. Delete all white spaces including leading blank space in each line (e.g. line 2), and replace such spaces by single tab except leading blank space

2. Then, align all columns to the right. But, output white space between columns should be identified by single tab, not white space, not multiple tab.

<input>
1990 8 9 2.31 3.12 4.343 112.113 0.123
1992 9 10 1.11 3.33 2.12 1.23 0.11
2011 10 11 2.56 7.23 3.11 2.33 0.1


Thanks,
  #2 (permalink)  
Old 08-08-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
The first one is simple...
Code:
$ awk -v OFS="\t" '$1=$1' file1
1990    8       9       2.31    3.12    4.343   112.113 0.123
1992    9       10      1.11    3.33    2.12    1.23    0.11
2011    10      11      2.56    7.23    3.11    2.33    0.1
But the second one is impossible. If you want to right-align, then you have to pad with something, e.g. spaces...
Code:
$ awk -v OFS="\t" '{for(i=1;i<=NF;i++)$i=sprintf("%7s",$i);print}' file1
   1990       8       9    2.31    3.12   4.343 112.113   0.123
   1992       9      10    1.11    3.33    2.12    1.23    0.11
   2011      10      11    2.56    7.23    3.11    2.33     0.1
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:51 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0