mod_sed 1.0.2

An Apache module that embeds a copy of the sed command

  Add it to your Download Basket!

 Add it to your Watch List!


Rate it!

What's new in mod_sed 1.0.2:

  • Fixed following 3 types of warnings :
  • warning: array subscript has type 'char'
  • warning: suggest parentheses around assignment used as truth value
  • warning C4018: '
Read full changelog
send us
an update
The Apache License 2.0 
Dominic Mitchell
ROOT \ Internet \ HTTP (WWW)
mod_sed is an Apache module that embeds a copy of the sed command. This means that you can automatically filter data without having to spawn a CGI process.

It probably doesn't have a lot of practical use, but I wrote it anyway. The main purpose was for me to learn how to write an apache module.


To build, you should just be able to type in "make". I'm still working on the portability aspects of this module, so it might not run on your system yet. All patches appreciated.

You'll need apxs(8) to build this module, because at present, I don't understand Apache's static configuration (again, patches welcome). Either edit the Makefile to specify the location of it, or put it on the command line like this:

% make APXS=/usr/local/sbin/apxs

If your system doesn't have an fgetln(3) call (to test, see if "man fgetln" returns anything), you'll also have to uncomment a line in the Makefile.

To install, "make install" should copy the to your data directory and put the correct lines in your httpd.conf to enable it.


This is all the documentation you get until I write some more, I'm afraid.

You'll need: A directory or file that you want to run sed over inside Apache. In my case, this is "/usr/local/www/data/sed/". Copies of the files are in the "eg" subirectory. The httpd.conf fragment I used looked like this:

< Directory /usr/local/www/data/sed >
SetHandler sed-handler
SedExtendedRegex on
#SedProgram "s/foo/BAR/g"
SedProgram /usr/local/www/data/sedscr
SedPathMap /foo /usr/local/www/data/
< /Directory >

You'll need to make sure that the directory you specify is visible from Apache. In fact, it's probably a good idea to do that /before/ installing this module...

The important bit to activate mod_sed is the "SetHandler" line. That enables all files under that directory to be passed through mod_sed.

The "SedExtendedRegex" line asks that sed use Enhanced Regexes instead of basic ones. If you don't know what that means, always include this line. For more details on the differences between basic regexes and extended regexes see re_format(7).

The "SedProgram" keyword can specify either a whole sed program (like you would give on the command line with -e) or a pathname to a file containing a sed program (this is generally the preferred option). To determine between the two, mod_sed will attempt to see if a file by that name exists, otherwise it'll try and compile it as a program.

The last command, "SedPathMap" takes two arguments: a PATH_INFO and another SedProgram argument. What it means is that when somebody requests a file:


The sed program in /usr/local/www/data/ will get run instead of the default in SedProgram. This can be very handy for serving up alternative versions of files.

Last updated on September 12th, 2010


#embed sed #Apache module #filter data #Apache #sed #embedded #filter

Add your review!