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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to trim the white space around a string in C program hxm1303 High Level Programming 18 10-17-2008 11:43 AM
wc of characters in a file ignoring white space sachin.gangadha UNIX for Dummies Questions & Answers 1 12-15-2007 06:13 PM
stripping white space... Zak Shell Programming and Scripting 7 10-09-2007 08:41 AM
How to get just the word and clean the white space? paulofp Shell Programming and Scripting 2 06-22-2007 07:28 PM
How to keep white space is being deleted using read keelba Shell Programming and Scripting 1 05-30-2002 03:15 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 08-09-2007
karlanderson karlanderson is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 4
Add white space to the end of a line with sed

Im trying to add 5 blank spaces to the end of each line in a file in a sed script. I can figure out who o put the spaces pretty much anywhere else but at the end.

thanks

Karl
  #2 (permalink)  
Old 08-09-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,787

Code:
 sed 's/$/     /' filename > newfilename

  #3 (permalink)  
Old 08-09-2007
karlanderson karlanderson is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 4
one more thing..

is the $ the last character of a line or the space just after the last character..

I thought i had tried that and it replaced the last string on each line with the 5 spaces. I could be wrong

thanks again for the help

karl
  #4 (permalink)  
Old 08-09-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
The '$' is not a physical character, but a representation of end of line.

Similar for '^' that represents the start of the line.
  #5 (permalink)  
Old 08-09-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
Quote:
Originally Posted by karlanderson View Post
one more thing..

is the $ the last character of a line or the space just after the last character..

I thought i had tried that and it replaced the last string on each line with the 5 spaces. I could be wrong

thanks again for the help

karl
'$' designates the 'end of line'.
doing 'man regexp' yields:

Code:
     4.2   A dollar sign ($) at the end  of  an  entire  RE  con-
           strains that RE to match a final segment of a line.

  #6 (permalink)  
Old 03-09-2009
bhaskar_m bhaskar_m is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 47
Adding to this post I just wanted to know how to add some characters other than special characters in every line of a file , say I want to add a "/" at the end of all lines in file. Kindly help. Thank you
  #7 (permalink)  
Old 03-09-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,330
Quote:
Originally Posted by bhaskar_m View Post
Adding to this post I just wanted to know how to add some characters other than special characters in every line of a file , say I want to add a "/" at the end of all lines in file. Kindly help. Thank you
Escape the character with a backslash:

Code:
sed 's/$/\//'

Regards
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 04:30 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