Skip to content

Instantly share code, notes, and snippets.

@Lemmings19
Last active May 26, 2016 22:35
Show Gist options
  • Save Lemmings19/afe7d9ac20483204cd14 to your computer and use it in GitHub Desktop.
Save Lemmings19/afe7d9ac20483204cd14 to your computer and use it in GitHub Desktop.
Add newline to end of files without them.
#!/bin/bash
echo "Adding newlines to files that don't have them."
echo "Each dot represents a file that has had a line added."
# Loop through files in the given directory with the given extensions
for f in $(find /var/www/project-name/ -name "*.php" -or -name "*.phtml" -or -name "*.js"); do
# If the file doesn't end in a new line, add one.
if [ "$(tail -c1 "$f"; echo x)" != $'\nx' ]; then
echo "" >>"$f"
echo -n "."
fi
done
echo "All done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment