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
Replace spaces between strings in a line with tab my_Perl Shell Programming and Scripting 1 07-20-2009 03:37 PM
Replace multiple dots (.) with spaces ( ) Monkey Dean Shell Programming and Scripting 6 05-03-2009 04:18 AM
Replace spaces tret Shell Programming and Scripting 12 10-07-2008 12:11 AM
Remove spaces between charc and replace it with ','. smc3 Shell Programming and Scripting 5 06-10-2008 01:08 PM
Replace spaces recursively prvnrk Shell Programming and Scripting 5 08-31-2007 05:37 AM

Reply
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 3 Weeks Ago
Prashant Jain Prashant Jain is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 5
Question how to replace . with 100 spaces

i have a file like::
$ cat space
asd
fghj
itkg

now i want to replace the next line with . and thn this . with the 100 spaces.

cat space | tr '\n' '.', it woked for me, to replce the new line to .

Now i want to replace this . with 100 spaces.

Thanks in advance.
  #2 (permalink)  
Old 3 Weeks Ago
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 536
Quote:
Originally Posted by Prashant Jain View Post
...
now i want to replace the next line with . and thn this . with the 100 spaces.
...
I guess you mean "newline" and not "next line".
Why an additional step in between ? Why not replace newlines with 100 spaces directly ?

Quote:
...
cat space | tr '\n' '.', it woked for me, to replce the new line to .

Now i want to replace this . with 100 spaces.

...
Again, why substitute by the "." first ?

tyler_durden
  #3 (permalink)  
Old 3 Weeks Ago
Prashant Jain Prashant Jain is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 5
If directly we can do it, it will be great. Can you please send me the command.
  #4 (permalink)  
Old 3 Weeks Ago
pogdorica's Avatar
pogdorica pogdorica is offline
Registered User
  
 

Join Date: Oct 2009
Location: Madrid
Posts: 55
Do you want to replace the last character with 100 spaces?

Code:
cat fichero | sed "s/$/`perl -e 'print \" \" x 100'`/"
  #5 (permalink)  
Old 3 Weeks Ago
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 536
Or using just Perl:

Code:
$
$ cat space
asd
fghj
itkg
$
$ perl -ne '$x = " "x10; s/\n/$x/g; print' space
asd          fghj          itkg          $
$
$
Replace 10 by 100 in the one-liner above.

tyler_durden
  #6 (permalink)  
Old 3 Weeks Ago
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
Quote:
Originally Posted by pogdorica View Post
Do you want to replace the last character with 100 spaces?

Code:
cat fichero | sed "s/$/`perl -e 'print \" \" x 100'`/"

Here i hope no need to use "cat".
  #7 (permalink)  
Old 3 Weeks Ago
Prashant Jain Prashant Jain is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 5
Thanks tyler_durden, it worked

Now there is one more issue, in some lines i have 10 charactes & in some there are 20chars.
no. of spaces should be 200 - number of character in a line.

if No. of chars are 20 thn there should be 180 spaces.

please help me on this also.

Thanks in advance
Reply

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 12:28 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