Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2002
    Location
    St. Louis, MO
    Posts
    1,378

    Searching for --- Adding Line with Sed

    How would I search for a pattern say one particular like then add something below it? In this case I want to write up a script that will save me some time installing an apache module so I want to use Sed to add something below the AddModule line with Include /usr/local/apache/conf/something.conf

  2. #2
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    sed -ie "s/Search for line/&\nExtra line to add/" filename.conf
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  3. #3
    Join Date
    Mar 2002
    Location
    St. Louis, MO
    Posts
    1,378
    thanks, I get an error actually doing so

    sed -ie "s/ExtendedStatus/&\nInclude /etc/httpd/conf/httpd/mod_security.conf" /etc/httpd/conf/httpd.conf
    sed: -e expression #1, char 31: Unknown option to `s'

  4. #4
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    I think you'd need to escape the slashes in your replacement string:
    Code:
    sed -ie "s/ExtendedStatus/&\nInclude \/etc\/httpd\/conf\/httpd\/mod_security.conf/" /etc/httpd/conf/httpd.conf
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  5. #5
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    Or, just use another delimiter, like %

    sed -ie "s%ExtendedStatus%&\n/etc/httpd/conf/httpd/mod_security.conf%" /etc/httpd/conf/httpd.conf
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  6. #6
    Join Date
    Mar 2002
    Location
    St. Louis, MO
    Posts
    1,378
    I forgot that after ExtendedStatus theres more it'll say On or Off so theres a space between Off/On so when using this it kinda screws up that line lol

Posting Permissions

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