Sed question
Mark Ovens
mark at ukug.uk.freebsd.org
Thu Apr 15 17:43:05 BST 2004
Matthew Seaman wrote:
> On Thu, Apr 15, 2004 at 04:43:40PM +0100, Mark Ovens wrote:
>> 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.
>
> If only. Unfortunately FreeBSD sed(1) does not grok '\n' as a
> character escape for new-line:
>
Duh! Yes, of course. I'd just been doing a similar thing, but using
Cygwin (under Windows) where '\n' does work. Sorry for the noise.
Mark
> % sed -e 's/\(domain.com-edit\)$/\1\nThis is new text/' <<E_O_T
> ? Some text
> ? Some more text
> ? substitution after domain.com-edit
> ? a bit more text
> ? the last text of all
> ? E_O_T
> Some text
> Some more text
> substitution after domain.com-editnThis is new text
> a bit more text
> the last text of all
>
> That just inserts a letter 'n'... This is the way to do it:
>
> % sed -e '/domain.com-edit$/a\\
> ? This is new text' <<E_O_T
> ? Some text
> ? Some more text
> ? substitution after domain.com-edit
> ? a bit more text
> ? the last text of all
> ? E_O_T
> Some text
> Some more text
> substitution after domain.com-edit
> This is new text
> a bit more text
> the last text of all
>
> (Those ?'s are shell prompts, so don't type them in literally)
>
> Cheers,
>
> Matthew
>
More information about the Ukfreebsd
mailing list