The UNIX and Linux Forums  

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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Adding character to spaces in a table Raynon Shell Programming and Scripting 15 05-23-2008 08:08 PM
how to append spaces(say 10 spaces) at the end of each line based on the length of th prathima UNIX for Dummies Questions & Answers 2 04-29-2008 02:43 PM
adding spaces for a variable value dnat Shell Programming and Scripting 2 02-26-2008 01:32 AM
Adding spaces to record nvenkat010 Shell Programming and Scripting 3 01-28-2008 09:24 AM
Adding Trailing Spaces to a file 222001459 UNIX for Dummies Questions & Answers 1 11-04-2004 11:23 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-23-2007
Registered User
 

Join Date: May 2005
Posts: 68
adding spaces to a line

Is there any command to add spaces to a lline....say i need 50 spaces between the data like

Code:
"aaabbbccc                                           dddeeefff"
or may be like this
"aaaabbbbbbcccccdddddeeeffff                              "

your help is appreciated.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-23-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,475
Code:
>cat file
aaa bbb
Code:
perl -e ' while (<>) { $a = " " x 20; $_ =~ s/ /$a/; print "$_"  } ' file
Reply With Quote
  #3 (permalink)  
Old 03-23-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,475
or for the second one you could do something like

Code:
perl -e ' while (<>) { $a = " " x 20; $_ =~ s/$/$a/; print "$_"  } ' filename
Reply With Quote
  #4 (permalink)  
Old 03-23-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,448
Code:
echo "aaa bbb" | awk '{ printf $1 
                       for (i=0; i<50; i++)   printf " " 
                       print $2
                     } '
Reply With Quote
  #5 (permalink)  
Old 03-23-2007
cfajohnson's Avatar
Registered User
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 487
Quote:
Originally Posted by mgirinath
Is there any command to add spaces to a lline....say i need 50 spaces between the data like

Code:
"aaabbbccc                                           dddeeefff"
or may be like this
"aaaabbbbbbcccccdddddeeeffff                              "

your help is appreciated.
If you need the data plus spaces to equal 50 characters:
Code:
printf "%-49s " "data 1" "data 2" "data 3" ...
printf "\n"
If you need 50 spaces between items:
Code:
printf "%s%50%" "data 1" " " "data 2" " " "data 3" " " ...
printf "\n"
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0