I am writing a script that compresses web files in order to reduce the size of a site and load on the server. After stripping out leading and trailing spaces I remove newlines and this causes problem with PHP files, since I get something like this:
where ... represents some PHP code. This is not valid. The following is needed - note the space before ...:
I am writing a script in Bash shell using sed for string conversions. I am sure Perl, Python or other scripting languages would be a better choice, but I am not familiar with them - even with sed I only scratch the surface. I did not know how to insert a space into an regex with sed, so I came up with the following solution:
-e "s/<?php[^ ]/jabudabu&/g" \
-e "s/jabudabu<?php/<?php\ /g" \
-e "s/<?[^(php) ]/jabudabu&/g" \
-e "s/jabudabu<?/<?\ /g"