Add newline to end of file

Revision as of 08:21, 26 September 2025 by Admin (talk | contribs) (Created page with "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. <syntaxhighlight lang="bash"> find . -name "*.yaml" -exec sh -c 'if [ -n "$(tail -c 1 "$1")" ]; then echo "" >> "$1"; fi' _ {} \;...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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' _ {} \;