Dec 20 2015

Trailing spaces and Missing Newlines (OSX)

Published by at 2:00 pm under Technology   

I frequently work on projects where various developers are using various editors or IDEs. Some of these tools, and it would be rude to name names, have completely broken notions of how files and lines ought to end. Those of us who been working with text files for many years mostly agree on the following.

  1. Every line, including the last one, ends in a newline character.
  2. No trailing white space.

Happily, git will point out problems of this nature, and many editors can easily fix a file once open. But I often need to fix a whole tree of files at once. I have various snippets and batch files around to do this, here is the relevant one-liner for OSX:

As usual, I recommend understanding such a line before running it, editing it to meet your specific needs, and using backups and/or source control to avoid data loss.

If you found this post useful, please link to it from your web site, mention it online, or mention it to a colleague.

No responses yet

Comments are closed.