Stripping Vertical Whitespace Using tr

The Translate command, tr, is available on all Unix-y systems, including Cygwin. tr -d will delete the specified characters from a stream. Several handy escape sequences are provided for stripping newlines, carriage returns, and form-feeds:

  • \f – form feed
  • \n – new line
  • \r – return

Since tr is deleting characters, not strings, we can simply specify all of these in a single command:

cat input.txt | tr -d \r\n\f > output.txt

Another way to assemble this command:

tr -d \r\n\f < input.txt > output.txt

About Jeff Fitzsimons

Jeff Fitzsimons is a software engineer in the California Bay Area. Technical specialties include C++, Win32, and multithreading. Personal interests include rock climbing, cycling, motorcycles, and photography.
This entry was posted in Linux, Scripting, Technology. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *