sed, awk, or something...help meeeeeeeeeee

Joerg Bergmann email at jbergmann.de
Mon Sep 28 19:20:47 UTC 2009


Am 28.09.2009 21:07, schrieb Sharpe, Sam J:
> 2009/9/28 Kanwar Ranbir Sandhu<m3freak at thesandhufamily.ca>:
>    
>> On Mon, 2009-09-28 at 19:33 +0100, Sharpe, Sam J wrote:
>>      
>>> Yes, but it involves reading the man page for sed - I'm not totally
>>> sure you are capable of doing that.
>>>
>>> I suggest looking at the output of "man sed", finding the section
>>> about the command "r" and then reading the next few lines.
>>>        
>> Oh my word.  I can't believe I missed that.  So, I've solved my little
>> problem with this:
>>
>> sed '/BB/R file2' file1
>>
>> Sweet!
>>      
> That alone doesn't fit your original specification:
>
> [sam at samlap Desktop]$ sed -e '/BB/R file2' file1
> AA
> BB
> BBBB1
> CC
> DD
>
> AA
> BB
> BBBB2
> CC
> DD
>
> You specified that BB was to be /replaced/ with BBBB1, so you will
> need to do this:
>
> [sam at samlap Desktop]$ sed -e '/BB/R file2' -e '/BB/d' file1
> AA
> BBBB1
> CC
> DD
>
> AA
> BBBB2
> CC
> DD
>
>    
This code may fail in case file 2 contains a line with BB only,
in that case the replacement will be removed too. Enclosed
you will find my suggestion for a C program (still unchecked).

Joerg
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: replace.c
Url: http://lists.fedoraproject.org/pipermail/users/attachments/20090928/4475dc20/attachment-0001.c 


More information about the users mailing list