MacOS – ‘cat’ not displaying line breaks

command linemacos

For some reason cat no longer shows line breaks when I use it, while all other tools (grep, more etc) do.

I am using iterm2 on OSX 10.11.4.

What could be causing this behaviour?

Example

I have a file test.txtcreated in vim:

this is a test
this is a test
this is a test

When I do cat test.txt the output is (note space in place of newline):

this is a test this is a test this is a test

Best Answer

These things can occur based on a whole bunch of small issues, either in the shell used, the terminal application used, the file format or something else altogether.

To triage, the following steps may be useful

  • run cat -vet test.txt to see whether there are additional characters in the file
  • run (echo a; echo b)|cat to see if it depending on the input data
  • switch terminal applications to see if this is the cause
  • run bash --noprofile to see whether something is lurking in the shell configuration

In my case someone had modified 'cat' behaviour in .bashrc