sed insert text on newline after pattern

sed insert text on newline after pattern

am 26.10.2007 21:16:55 von peter sands

Hi,

I have this file, I need to insert a 3 hash marks after the pattern
'EVENT' is found on the next line
so, if I have:

WPAR EVENT
date time..etc ...


The file should become:
WPAR EVENT
###
date time..etc..

I have tried messing with the insert/append mode , but I always get
errors
Any pointers please.

Thanks
Pete.

Re: sed insert text on newline after pattern

am 26.10.2007 21:32:34 von Ed Morton

peter sands wrote:
> Hi,
>
> I have this file, I need to insert a 3 hash marks after the pattern
> 'EVENT' is found on the next line
> so, if I have:
>
> WPAR EVENT
> date time..etc ...
>
>
> The file should become:
> WPAR EVENT
> ###
> date time..etc..
>
> I have tried messing with the insert/append mode , but I always get
> errors
> Any pointers please.
>
> Thanks
> Pete.
>

Just use awk:

awk '{print} /EVENT/{print "###"}' file

Ed.

Re: sed insert text on newline after pattern

am 26.10.2007 21:35:49 von Glenn Jackman

At 2007-10-26 03:16PM, "peter sands" wrote:
> Hi,
>
> I have this file, I need to insert a 3 hash marks after the pattern
> 'EVENT' is found on the next line
> so, if I have:
>
> WPAR EVENT
> date time..etc ...
>
>
> The file should become:
> WPAR EVENT
> ###
> date time..etc..

sed '/EVENT/ a ###' filename


--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry

Re: sed insert text on newline after pattern

am 26.10.2007 22:02:46 von Stephane CHAZELAS

2007-10-26, 19:35(+00), Glenn Jackman:
> At 2007-10-26 03:16PM, "peter sands" wrote:
>> Hi,
>>
>> I have this file, I need to insert a 3 hash marks after the pattern
>> 'EVENT' is found on the next line
>> so, if I have:
>>
>> WPAR EVENT
>> date time..etc ...
>>
>>
>> The file should become:
>> WPAR EVENT
>> ###
>> date time..etc..
>
> sed '/EVENT/ a ###' filename

That's GNU sed syntax.

The standard syntax is

sed '/EVENT/a\
###' filename

--
Stéphane

Re: sed insert text on newline after pattern

am 30.10.2007 10:10:18 von Michael Tosch

Stephane CHAZELAS wrote:
> 2007-10-26, 19:35(+00), Glenn Jackman:
>> At 2007-10-26 03:16PM, "peter sands" wrote:
>>> Hi,
>>>
>>> I have this file, I need to insert a 3 hash marks after the pattern
>>> 'EVENT' is found on the next line
>>> so, if I have:
>>>
>>> WPAR EVENT
>>> date time..etc ...
>>>
>>>
>>> The file should become:
>>> WPAR EVENT
>>> ###
>>> date time..etc..
>> sed '/EVENT/ a ###' filename
>
> That's GNU sed syntax.
>
> The standard syntax is
>
> sed '/EVENT/a\
> ###' filename
>

Alternative:

sed '/EVENT/{p;s/.*/###/;}' filename


--
Michael Tosch @ hp : com

Re: sed insert text on newline after pattern

am 02.11.2007 10:02:12 von Rakesh Sharma

On Oct 27, 12:16 am, peter sands wrote:

[snip]...

sed -e '
/EVENT/\!b
G; s/$/###/
' < input_filename