Results 1 to 3 of 3

Thread: Like to be able to use sed to add new line after line match

  1. #1
    Join Date
    Nov 2006
    Location
    There and back again
    Beans
    1,097

    Like to be able to use sed to add new line after line match

    Been looking around for this but haven't been able to find anything.

    I'd like to be able to add a new line after matching text in a line.

    For example, say I got:

    Code:
    #output databases: mysql, snort, password yourpassword, more, blah
    and after this line I'd like to add:

    Code:
    #output databases: mysql, snort, password yourpassword, more, blah
    darn right
    So far I got:

    Code:
    sed -i -e 's`^#output database$`#out$ \
    darn right`g' file
    As you can see I'm at a loss as what the second value should be. I'd like to be able to match this generically. Is this possible? Also does the first value (^output database$) appear right?
    Last edited by Gen2ly; August 6th, 2009 at 06:03 AM.

  2. #2
    Join Date
    Nov 2006
    Location
    There and back again
    Beans
    1,097

    Re: Like to be able to use sed to add new line after line match

    Ah i got it (Gentoo Developer's guides are awesome):

    Code:
    sed -i -e `^text to match$/a text to add on new line` file
    Gotta like sed, Doh!

  3. #3
    Join Date
    Feb 2011
    Beans
    6

    Re: Like to be able to use sed to add new line after line match

    Thanks
    Btw heads up, the forwardslash has been removed in the above but the link is good

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •