+ Reply to Thread
Results 1 to 6 of 6

sed insert text on newline after pattern

  1. 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.


  2. 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.

  3. 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

  4. 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

  5. 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 @ hp : com

  6. Re: sed insert text on newline after pattern

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

    [snip]...

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


+ Reply to Thread