Re: Need help with reading in a fileto replace a line, using sed

[email protected]
Newsgroups gmane.editors.sed.user
Message-ID <488998867.167308.1362433608526.JavaMail.root@sz0115a.emeryville.ca.mail.comcast.net>
Thanks.  That's great solution! 

----- Original Message -----
From: "Davide Brini" <[email protected]> 
On Mon, 4 Mar 2013 18:51:34 +0000 (UTC), [email protected] wrote: 

> 
> 
> Hi.  I have a shell script that uses ed to replace a line in file 
> textfile1 
> 
> containing the pattern xxxxx with the contents of a file (textfile2). 
> 
> It does this by locating the line, deleting the line, then reading in 
> textfile2. 
> 
> The only concern with textfile2 is that it might also contain the same 
> pattern (xxxxx). 
> 
> textfile1 will only have this pattern (xxxxx) occur once. 
> 
> 
> 
> I am wondering if someone knows a way to do this same thing using sed. 
> 
> Remember that textfile2 might also contain the pattern xxxxx. 

The (imho) weird behavior of "r" in sed is actually useful here: 

sed -e '/xxxxx/{ r textfile2' -e 'd; }' textfile1 

-- 
D. 




[Non-text portions of this message have been removed]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.