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
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 17 01-28-2009 04:10 PM
Adding character to spaces in a table Raynon Shell Programming and Scripting 15 05-23-2008 11:08 PM
adding spaces for a variable value dnat Shell Programming and Scripting 2 02-26-2008 05:32 AM
Adding spaces to record nvenkat010 Shell Programming and Scripting 3 01-28-2008 01:24 PM
Adding Trailing Spaces to a file 222001459 UNIX for Dummies Questions & Answers 1 11-04-2004 03:23 PM

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

Join Date: May 2005
Posts: 69
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.
  #2 (permalink)  
Old 03-23-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
Code:
>cat file
aaa bbb
Code:
perl -e ' while (<>) { $a = " " x 20; $_ =~ s/ /$a/; print "$_"  } ' file
  #3 (permalink)  
Old 03-23-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
or for the second one you could do something like

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

Join Date: Sep 2006
Posts: 2,513
Code:
echo "aaa bbb" | awk '{ printf $1 
                       for (i=0; i<50; i++)   printf " " 
                       print $2
                     } '
  #5 (permalink)  
Old 03-23-2007
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
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"
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 10:27 AM.


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