How do you produce a CR/LF anywhere in a text document created in linux OS so that it can be copied and pasted into a windows text editor or onto the web and retain the CR/LF to be read and acted upon in a windows OS or on the web? A for instance would be ascii art that requires CR/LF to keep character alignment accurate. Producing ascii art in linux with CR/LF codes that can be utilized in windows or online.
4 Answers
Don't worry about it, use standard Unix/(GNU) Linux
tools, and then run
unix2dos
on your Unix file.

- 28,816
This can easily be done with vim
.
If you want to convert all line breaks into CR/LFs in a file,
- Open the file in vim (
vim file.txt
). - Convert the file to DOS format (which means CR/LF line breaks):
:e ++ff=dos
. - Save and quit (Shift+Z Shift+Q or
:wq
).
If you simply want to insert a single CR/LF line break,
- Open the file in vim (
vim file.txt
). - Navigate to the line that you want to insert a CR/LF line break after (if you're not familiar with vim, you can just use the up and down arrow keys).
- Enter insert mode, appending to the end of the line (Shift+A).
- Insert a carriage return character (Ctrl+V Ctrl+M).
- Insert a line feed character (Return).
- Exit insert mode (Esc).
- Save and quit (Shift+Z Shift+Q or
:wq
).

- 3,093
-
ok for clarification (my fault) I am using linux simple text editor and want the CR and the LF to be stored so that when pasted into a MS text editor or into a web chat the CR and LF are acted upon and transferred to the receiving environment. – Rocket Jun 08 '15 at 04:09
Edit: So what you actually want to know is how to convert a file from Unix to Windows line endings. Do it from the command line, not the editor, with the following one-liner. It will work correctly even if you run it on the same file multiple times.
perl -pe 's/\r?\n/\r\n/' unix-file.txt > windows-file.txt
You can view a file with od -c
to see its newline characters.
PS. By the way some editors will let you save in DOS format and/or preserve the existing line endings (but who knows what you're using.)
Here's the answer for what you thought you wanted:
If you really want to enter them explicitly, you need to know two things: The control codes for CR and LF, and how your editor or whatever lets you enter literal control codes.
CR is
^M
(control+M). LF is^L
(control+L).Find out how your editor "escapes" the next thing you'll type. In emacs that's control+Q (
^Q
, orC-q
in emacs notation), so you'd type^Q ^M
to enter a CR. A more common escape (e.g. in vim and on the bash prompt) is^V
.
Note also that LF is the end of line, so you'll probably not see it after it's entered. But it's there.

- 5,759
you could try Geany, it's a gui type text editor, and line endings are one of the many things you can edit.

- 101