Stripping Vertical Whitespace Using tr

June 16th, 2008 | by Jeff Fitzsimons |

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

Post a Comment