Sed question

Mark Ovens mark at ukug.uk.freebsd.org
Thu Apr 15 16:43:40 BST 2004


Dave Tiger wrote:

> Hi Sam,
> 
>  cat filename | sed -e "s/domain.com-edit\/1s/^L^Mtext to add/" filename
> 

You can't write to the file you're reading from, try:

mv filename filename.bu; cat filename.bu | sed
's/\(domain.com-edit\)$/\1\nThis is new text/' > filename

All that is on one line of course.

HTH

Mark

> Added the pipe as a friend called me up and told me to but all I get is the
> file streaming to the screen and not writing the as expected text :-(
> 
> I know I am so close to this and I ask if you or the list have the answer to
> this so I can move on. 
> 
> I took out the $ in your exapmle because it errored say invalid variable
> name.
> 
> Thank you for your previous help.
> 
> Dave C
> 
> -----Original Message-----
> From: Sam [mailto:freebsd at pikesley.org] 
> Sent: 15 April 2004 15:37
> To: Dave Tiger
> Cc: freebsd-users at uk.freebsd.org
> Subject: Re: Sed question
> 
> 
> On Thu, 2004-04-15 at 15:25, Dave Tiger wrote:
>> Hi Again,
>> 
>> Sorry to be a bore but I cant get my head around sed and adding text 
>> to a file using it.
>> 
>> I need to find the instance of "domain.com-edit" which is at the end 
>> of a line in a file and add a line of text under it.
>> 
>> Sed -e "domain.com-edit" -e "s/text to add/g" filename
> 
> 	sed -e "s/\(domain.com-edit\)$/\1^L^Mtext to add/" <filename>
> 
> Where ^L^M is actually the following sequence: 
> 
> 	"Ctrl-V Ctrl-L Ctrl-V Ctrl-M"
> 
> I'm sure there's a sed ninja reading this who knows a better way to do it,
> but it Works For Me...
> 
>>  
>> 
>> Dose not work, I got the example of a website.
>> 
>> Any help with this last piece of the puzzle is appreciated.
>> 
>> Thank you in advance
>> 
>> Dave C
>> 
>> ---
>> Outgoing mail is certified Virus Free.
>> Checked by AVG anti-virus system (http://www.grisoft.com).
>> Version: 6.0.657 / Virus Database: 422 - Release Date: 13/04/2004
>>  
>> 
>> 
>> ------ FreeBSD UK Users' Group  -  Mailing List ------ 
>> http://listserver.uk.freebsd.org/mailman/listinfo/freebsd-users






More information about the Ukfreebsd mailing list