sed insert text on newline after pattern

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.
peter sands [ Fr, 26 Oktober 2007 21:16 ] [ ID #1854900 ]

Re: sed insert text on newline after pattern

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.
Ed Morton [ Fr, 26 Oktober 2007 21:32 ] [ ID #1854901 ]

Re: sed insert text on newline after pattern

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
Glenn Jackman [ Fr, 26 Oktober 2007 21:35 ] [ ID #1854902 ]

Re: sed insert text on newline after pattern

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
Stephane CHAZELAS [ Fr, 26 Oktober 2007 22:02 ] [ ID #1854904 ]

Re: sed insert text on newline after pattern

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 [at] hp : com
Michael Tosch [ Di, 30 Oktober 2007 10:10 ] [ ID #1857401 ]

Re: sed insert text on newline after pattern

On Oct 27, 12:16 am, peter sands <peter_sa... [at] techemail.com> wrote:

[snip]...

sed -e '
/EVENT/\!b
G; s/$/###/
' < input_filename
Rakesh Sharma [ Fr, 02 November 2007 10:02 ] [ ID #1860550 ]
Linux » comp.unix.shell » sed insert text on newline after pattern

Vorheriges Thema: Changing mtime of a symlink
Nächstes Thema: Provide a link to huge files | ftp to windows