rmphpclosingtag.sh 819 B

1234567891011121314151617181920212223
  1. #!/bin/bash
  2. # vim:ft=sh:ts=3:sts=3:sw=3:et:
  3. ###
  4. # Strips the closing php tag `?>` and any following blank lines from the
  5. # end of any PHP file in the current working directory and sub-directories. Files
  6. # with non-whitespace characters following the closing tag will not be affected.
  7. #
  8. # Author: Bryan C. Geraghty <bryan@ravensight.org>
  9. # Date: 2009-10-28
  10. # Source: http://bryan.ravensight.org/2010/07/remove-php-closing-tag/
  11. ##
  12. FILES=$(pcregrep -rnM --include='^.*\.php$' '^\?\>(?=([\s\n]+)?$(?!\n))' .);
  13. for MATCH in $FILES;
  14. do
  15. FILE=`echo $MATCH | awk -F ':' '{print $1}'`;
  16. TARGET=`echo $MATCH | awk -F ':' '{print $2}'`;
  17. LINE_COUNT=`wc -l $FILE | awk -F " " '{print $1}'`;
  18. echo "Removing lines ${TARGET} through ${LINE_COUNT} from file $FILE...";
  19. sed -i "${TARGET},${LINE_COUNT}d" $FILE;
  20. done;