Add white space to the end of a line with sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add white space to the end of a line with sed
# 1  
Old 08-09-2007
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  
Old 08-09-2007
Code:
 sed 's/$/     /' filename > newfilename

This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 08-09-2007
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  
Old 08-09-2007
The '$' is not a physical character, but a representation of end of line.

Similar for '^' that represents the start of the line.
# 5  
Old 08-09-2007
Quote:
Originally Posted by karlanderson
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  
Old 03-09-2009
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  
Old 03-09-2009
Quote:
Originally Posted by bhaskar_m
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Putting white Space at the end of the string

Hi Guys, Hope, you all are doing good out there. I am writing a shell script and currrint in need of your help. This is what I need to do; I have position based plain file. One of the fields is 15 character long. I need to fill that field. The problem is that the value is dynamic, it could... (4 Replies)
Discussion started by: singh.chandan18
4 Replies

2. Shell Programming and Scripting

Add white space

hi guys how can i add spacein file name with sed if strings have no space around dash input 19-20 ( 18-19 ) ABC-EFG output after add white space 19 - 20 (18 - 19 ) ABC - EFG thx in advance (2 Replies)
Discussion started by: mhs
2 Replies

3. Shell Programming and Scripting

How to add a line to the end of a set of files without using sed command?

I understand that the SED command reads all the lines in the file before adding a required line to the end of the file. Is there another command that adds a line to the end of files without reading the entire file.... SED is increasing the processing time as the number of lines in each of the... (1 Reply)
Discussion started by: Kanch
1 Replies

4. UNIX for Dummies Questions & Answers

sed - Add a variable line to the end of a block beginning with a regex

Hi, Need some help with sed. I have a file that has sections : e.g. a=blah b=blah d=blah e=blah There's many sections in the file. (1 Reply)
Discussion started by: andyatit
1 Replies

5. Shell Programming and Scripting

How to Add space at the end of each line in linux

hi,. I am writing a small script in csh... Can any one tel me how to add space at end of each line in a file (9 Replies)
Discussion started by: Manju87
9 Replies

6. Shell Programming and Scripting

Delete white space using sed

Hi , I have a file with contents as below group1 = aaaaa, bbbbb, ccccc, aaa group2=aaa, bbbbb, ccccc, aaaaa group3 = bbbbb, aaa, ccccc, aaaaa group4 = bbbbb, aaa,ccccc, aaaaa I want to search for "aaa" and the output should be as below group1 = aaaaa, bbbbb, ccccc group2= bbbbb, ccccc,... (3 Replies)
Discussion started by: anil8103
3 Replies

7. Shell Programming and Scripting

sed + white space

Hi, What sed command (if sed is the right command) can remove ALL white space from my file. I have a csv, except I want to remove all white space between commas and characters. My idea (without testing) sed 's/ //g' Is there a better way? (18 Replies)
Discussion started by: mcclunyboy
18 Replies

8. Shell Programming and Scripting

sed : replace space and end-of-line

Hi ! I'm rather new with sed ... learned a lot already by googling etc ... The following script should replace all spaces and ends-of-lines with "something (see below). #!/bin/bash i=0 while read line do fam="H`printf "%06d" $i`" echo $line | sed -e 's//\t'$fam'\n/g' i=$(($i+1))... (7 Replies)
Discussion started by: jossojjos
7 Replies

9. Shell Programming and Scripting

Want to use sed to add some parameters at the end of the line

Hello All, I have a doubt in sed, i want to add some parameter at the end of the tag inside a xml tag. how to i do that. so i want to add Results="true" value="high" inside the xml tag. Orignal <execute description="reboot"> <execute description="Stop Servlet"> After adding the... (5 Replies)
Discussion started by: asirohi
5 Replies

10. UNIX for Dummies Questions & Answers

SED with White Space

Dear Members, Suppose i have a variable test which stores a string as below: test='John drives+++++++++a+++++car' now i want to use sed on the above variable and replace + with a white space, so that i get echo $test should give me 'john drives a car' Between... (1 Reply)
Discussion started by: sandeep_1105
1 Replies
Login or Register to Ask a Question