Add newline to end of file

From Freephile Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

For yaml files, there should always be a newline character at the end of the file. It's easy to overlook, and some editors are misconfigured to remove trailing newlines, meaning it can be a battle to keep your yaml syntactically correct. When you can't use tools like yamllint to fix things, here's a one-liner that does the job.

find . -name "*.yaml" -exec sh -c 'if [ -n "$(tail -c 1 "$1")" ]; then echo "" >> "$1"; fi' _ {} \;