Solução alternativa feia testada no Ubuntu Apache / 2.4.18, usando o subconjunto suportado do sed:
$ cat tmp line3 $ sed "h;s/.*/line1/;p;s/.*/line2/;G;p;s/.*/line4/" tmp line1 line2 line3 line4 $ cat week sunday wednesday friday $ sed "2{h;s/.*/monday/;p;s/.*/tuesday/;G;p;s/.*/thursday/;n;p;s/.*/saturday/;}" week sunday monday tuesday wednesday thursday friday saturday
these work too as \n is still recognised in search string "G;H;g;s/\n/line1&line2&/;s/\n$/&line4/" "2{G;H;g;s/\n/monday&tuesday&/;s/\n$/&thursday/;n;p;s/.*/saturday/;}"
$ #sudo a2enmod sed $ #apache2.conf <Location /txt/> AddOutputFilter Sed txt OutputSed "G;H;g;s/\n/line1&line2&/;s/\n$/&line4/" </Location> $ service apache2 reload $ wget localhost/txt/tmp.txt -qO - line1 line2 line3 line4
$ #sudo a2enmod ext_filter $ #apache2.conf ExtFilterDefine external_sed mode=output intype=text/plain cmd="/bin/sed :0;N;$!b0;s/\n//g" <Location /txt/> SetOutputFilter external_sed </Location> $ service apache2 reload $ wget localhost/txt/week.txt -qO - sundaywednesdayfriday
Veja também: # 1 , #2