I have a .txt file originated from Windows, so its line endings are \r\n. Running cat or echo on that file makes those control characters go away. How can I display the file (even in raw bytes if possible) while preserving the original control characters from Windows?

  • 1
    pbcopy < dosfile and then pbpaste > dosfile.copy creates identical files, including the CRNL line endings – glenn jackman Nov 22 '19 at 1:30
  • @glennjackman Thanks. Such a simple solution. If you submit an answer I'll accept it. – sargas Nov 26 '19 at 20:46

pbcopy will take input piped or redirected into it, and store it in a "pasteboard" (i.e. clipboard). So to copy a file verbatim, use a redirection:

pbcopy < dosfile

To paste, use Commandv or

pbpaste | some_command
pbpaste > some_file

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .