I need to create a dos format text file on Unix, whose end of line character is \r\n.
In Unix and vi, I can see (via "set list") the $ end of line character.
When I convert the file to DOS format using:
perl -i -pne "s/\n/\r\n/g" i.txt
I get end-of-line as: ^M$.
This is close, but what I need is a file ending in \r\n (ie: ^M only).
Example i.txt file (say, if have set list enabled in vi):
starting text line one$
starting text line two$
converted produces:
starting text line one^M$
starting text line two^M$
need:
starting text line one^M
starting text line two^M
So I need the dos single-character representation for end of line. unix2dos didn't help. Suggestions?
The $
does not represent a character. It simply shows where the line ends.
The purpose of this is to show trailing whitespace, like in this example explaining uniq
output:
$ uniq file
foo
foo
$ cat -vE file
foo$
foo $
Since it's just a visual marker, asking how to delete it doesn't make sense. It was never there. If you want \r\n
, then ^M$
is correct. Here's an example of this, verifiable by the hex dump:
$ cat -vE file
foo^M$
bar^M$
$ od -c -t x1 < file
0000000 f o o \r \n b a r \r \n
66 6f 6f 0d 0a 62 61 72 0d 0a