Command Line – How to Put File into Clipboard Without Losing Control Characters

command lineencodingwindows

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?

Best Answer

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