1<?xml version="1.0" encoding="ISO-8859-1"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!-- 4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 5 This file is generated from xml source: DO NOT EDIT 6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 7 --> 8<title>mod_sed - Apache HTTP Server</title> 9<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" /> 10<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" /> 11<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="/style/css/prettify.css" /> 12<script src="/style/scripts/prettify.min.js" type="text/javascript"> 13</script> 14 15<link href="/images/favicon.ico" rel="shortcut icon" /></head> 16<body> 17<div id="page-header"> 18<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p> 19<p class="apache">Apache HTTP Server Version 2.4</p> 20<img alt="" src="/images/feather.gif" /></div> 21<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div> 22<div id="path"> 23<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.4</a> > <a href="./">Modules</a></div> 24<div id="page-content"> 25<div id="preamble"><h1>Apache Module mod_sed</h1> 26<div class="toplang"> 27<p><span>Available Languages: </span><a href="/en/mod/mod_sed.html" title="English"> en </a> | 28<a href="/fr/mod/mod_sed.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a></p> 29</div> 30<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Filter Input (request) and Output (response) content using <code>sed</code> syntax</td></tr> 31<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Experimental</td></tr> 32<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>sed_module</td></tr> 33<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_sed.c sed0.c sed1.c regexp.c regexp.h sed.h</td></tr> 34<tr><th><a href="module-dict.html#Compatibility">Compatibility:</a></th><td>Available in Apache 2.3 and later</td></tr></table> 35<h3>Summary</h3> 36 37<p> 38<code class="module"><a href="/mod/mod_sed.html">mod_sed</a></code> is an in-process content filter. The <code class="module"><a href="/mod/mod_sed.html">mod_sed</a></code> filter implements the <code>sed</code> editing 39commands implemented by the Solaris 10 <code>sed</code> 40program as described in the <a href="http://www.gnu.org/software/sed/manual/sed.txt">manual 41page</a>. However, unlike <code>sed</code>, <code class="module"><a href="/mod/mod_sed.html">mod_sed</a></code> doesn't take data from 42standard 43input. Instead, the filter acts on the entity data sent between client and 44server. <code class="module"><a href="/mod/mod_sed.html">mod_sed</a></code> can be used as an input or output filter. <code class="module"><a href="/mod/mod_sed.html">mod_sed</a></code> is a 45content filter, which means that it cannot be used to modify client or 46server http headers. 47</p> 48<p> 49The <code class="module"><a href="/mod/mod_sed.html">mod_sed</a></code> output filter accepts a chunk of data, executes the <code>sed</code> scripts on the data, and generates the output which is passed to the next filter in the chain. 50</p> 51 52<p> 53The <code class="module"><a href="/mod/mod_sed.html">mod_sed</a></code> input filter reads the data from the next filter in the chain, executes the <code>sed</code> scripts, and returns the generated data to the caller filter in the filter chain. 54</p> 55 56<p> 57Both the input and output filters only process the data if newline characters are seen in the content. At the end of the data, the rest of the data is treated as the last line. 58</p> 59 60<p>A tutorial article on <code class="module"><a href="/mod/mod_sed.html">mod_sed</a></code>, and why it is more powerful than simple 61string or regular expression search and replace, is available <a href="https://blogs.oracle.com/basant/entry/using_mod_sed_to_filter">on 62the author's blog</a>.</p> 63 64</div> 65<div id="quickview"><h3 class="directives">Directives</h3> 66<ul id="toc"> 67<li><img alt="" src="/images/down.gif" /> <a href="#inputsed">InputSed</a></li> 68<li><img alt="" src="/images/down.gif" /> <a href="#outputsed">OutputSed</a></li> 69</ul> 70<h3>Topics</h3> 71<ul id="topics"> 72<li><img alt="" src="/images/down.gif" /> <a href="#sampleconf">Sample Configuration</a></li> 73<li><img alt="" src="/images/down.gif" /> <a href="#sed_commands">Sed Commands</a></li> 74</ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div> 75<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 76<div class="section"> 77<h2><a name="sampleconf" id="sampleconf">Sample Configuration</a></h2> 78 <div class="example"><h3>Adding an output filter </h3><pre class="prettyprint lang-config"># In the following example, the sed filter will change the string 79# "monday" to "MON" and the string "sunday" to SUN in html documents 80# before sending to the client. 81<Directory "/var/www/docs/sed"> 82 AddOutputFilter Sed html 83 OutputSed "s/monday/MON/g" 84 OutputSed "s/sunday/SUN/g" 85</Directory></pre> 86</div> 87 88 <div class="example"><h3>Adding an input filter </h3><pre class="prettyprint lang-config"># In the following example, the sed filter will change the string 89# "monday" to "MON" and the string "sunday" to SUN in the POST data 90# sent to PHP. 91<Directory "/var/www/docs/sed"> 92 AddInputFilter Sed php 93 InputSed "s/monday/MON/g" 94 InputSed "s/sunday/SUN/g" 95</Directory></pre> 96</div> 97</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 98<div class="section"> 99<h2><a name="sed_commands" id="sed_commands">Sed Commands</a></h2> 100 <p> 101 Complete details of the <code>sed</code> command can be found from the 102 <a href="http://www.gnu.org/software/sed/manual/sed.txt">sed manual 103page</a>. 104 </p> 105 <dl> 106 <dt><code>b</code></dt> 107 <dd>Branch to the label specified (similar to goto).</dd> 108 <dt><code>h</code></dt> 109 <dd>Copy the current line to the hold buffer.</dd> 110 <dt><code>H</code></dt> 111 <dd>Append the current line to the hold buffer.</dd> 112 <dt><code>g</code></dt> 113 <dd>Copy the hold buffer to the current line.</dd> 114 <dt><code>G</code></dt> 115 <dd>Append the hold buffer to the current line.</dd> 116 <dt><code>x</code></dt> 117 <dd>Swap the contents of the hold buffer and the current line.</dd> 118 </dl> 119</div> 120<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 121<div class="directive-section"><h2><a name="InputSed" id="InputSed">InputSed</a> <a name="inputsed" id="inputsed">Directive</a></h2> 122<table class="directive"> 123<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sed command to filter request data (typically <code>POST</code> data)</td></tr> 124<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>InputSed <var>sed-command</var></code></td></tr> 125<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>directory, .htaccess</td></tr> 126<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr> 127<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_sed</td></tr> 128</table> 129 <p>The <code class="directive">InputSed</code> directive specifies the <code>sed</code> command 130 to execute on the request data e.g., <code>POST</code> data. 131 </p> 132 133</div> 134<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 135<div class="directive-section"><h2><a name="OutputSed" id="OutputSed">OutputSed</a> <a name="outputsed" id="outputsed">Directive</a></h2> 136<table class="directive"> 137<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sed command for filtering response content</td></tr> 138<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>OutputSed <var>sed-command</var></code></td></tr> 139<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>directory, .htaccess</td></tr> 140<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr> 141<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_sed</td></tr> 142</table> 143 <p>The <code class="directive">OutputSed</code> directive specifies the <code>sed</code> 144 command to execute on the response. 145 </p> 146 147</div> 148</div> 149<div class="bottomlang"> 150<p><span>Available Languages: </span><a href="/en/mod/mod_sed.html" title="English"> en </a> | 151<a href="/fr/mod/mod_sed.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a></p> 152</div><div class="top"><a href="#page-header"><img src="/images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div> 153<script type="text/javascript"><!--//--><![CDATA[//><!-- 154var comments_shortname = 'httpd'; 155var comments_identifier = 'http://httpd.apache.org/docs/2.4/mod/mod_sed.html'; 156(function(w, d) { 157 if (w.location.hostname.toLowerCase() == "httpd.apache.org") { 158 d.write('<div id="comments_thread"><\/div>'); 159 var s = d.createElement('script'); 160 s.type = 'text/javascript'; 161 s.async = true; 162 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier; 163 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s); 164 } 165 else { 166 d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>'); 167 } 168})(window, document); 169//--><!]]></script></div><div id="footer"> 170<p class="apache">Copyright 2014 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p> 171<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!-- 172if (typeof(prettyPrint) !== 'undefined') { 173 prettyPrint(); 174} 175//--><!]]></script> 176</body></html>