Last active
December 25, 2015 18:59
-
-
Save staabm/7024524 to your computer and use it in GitHub Desktop.
strip php closing tags from all files within a directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# vim:ft=sh:ts=3:sts=3:sw=3:et: | |
# origin taken from http://bryan.ravensight.org/2010/07/remove-php-closing-tag/ | |
# with some custom changes. | |
### | |
# Strips the closing php tag `?>` and any following blank lines from the | |
# end of any PHP file in the current working directory and sub-directories. Files | |
# with non-whitespace characters following the closing tag will not be affected. | |
# | |
# Author: Bryan C. Geraghty <[email protected]> | |
# Date: 2009-10-28 | |
## | |
for i in {1..15} | |
do | |
FILES=$(pcregrep -rnM --include='^.*\.php$' '^\?\>(?=([\s\n]+)?$(?!\n))' .); | |
for MATCH in $FILES; | |
do | |
FILE=`echo $MATCH | awk -F ':' '{print $1}'`; | |
TARGET=`echo $MATCH | awk -F ':' '{print $2}'`; | |
LINE_COUNT=`wc -l $FILE | awk -F " " '{print $1}'`; | |
echo "Removing lines ${TARGET} through ${LINE_COUNT} from file $FILE..."; | |
sed -i "${TARGET},${LINE_COUNT}d" $FILE; | |
done; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in case you have several newlines behind
?>
make sure to exec the script multiple times!