sed delete all lines after

Objective: Prep dev httpd.conf for production


  1. Remove jenkins virtual host entry (which starts with a comment line “#Start Jenkins”)
  2. Replace .dev with nothing (ex: becomes
  3. Replace debug with error (ex: Loglevel debug becomes Loglevel error)

Sed to remove lines after match

In this example we will use sed delete all lines after the words “Start Jenkins” (from an httpd.conf file)

cat /etc/httpd/conf/httpd.conf | sed -n '/Start Jenkins/q;p'

Replace “.dev” with nothing

perl -pi -e 's~dev\.~~g' /tmp/file

Replace “debug” with “error”

perl -pi -e 's~debug~error~g' /tmp/file

Put it all together

cat /etc/httpd/conf/httpd.conf | sed -n '/Start Jenkins/q;p' > \
/tmpfile; perl -pi -e 's~dev\.~~g' \
/tmpfile; perl -pi -e 's~debug~error~g' /tmpfile

Leave a Reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>