521

Vim shows ^M on every line ending.

How do I replace this with a normal line break in a file opened in Vim?

Henke
  • 4,445
  • 3
  • 31
  • 44
ByteNirvana
  • 5,640
  • 4
  • 21
  • 20
  • 1
    possible duplicate of [Convert DOS line endings to Linux line endings in vim](http://stackoverflow.com/questions/82726/convert-dos-line-endings-to-linux-line-endings-in-vim) – cfi Sep 11 '15 at 11:26
  • 3
    Please change the solution to the [fileformat change](http://stackoverflow.com/a/22816221/131120) because that's the most clean solution. – erikbstack Oct 13 '16 at 20:20
  • 2
    I know this question is about vim, but some other Google searches also land in this thread. So, if you have Eclipse installed on your system you could convert the line delimiter for either a single file or a complete folder tree of files with a few clicks: https://stackoverflow.com/a/7019737/1364747 – Teddy Jul 04 '17 at 06:18
  • I like how you call normal line breaks "normal" -- in contrast to those ^M line breaks :-) – DerMike May 06 '20 at 11:57
  • @DerMike I guess all those fancy standard Internet protocols are just abnormal then? – 0xC0000022L Jan 10 '23 at 17:34

38 Answers38

615

Command

:%s/<Ctrl-V><Ctrl-M>/\r/g

Where <Ctrl-V><Ctrl-M> means type Ctrl+V then Ctrl+M.

Explanation

:%s

substitute, % = all lines

<Ctrl-V><Ctrl-M>

^M characters (the Ctrl-V is a Vim way of writing the Ctrl ^ character and Ctrl-M writes the M after the regular expression, resulting to ^M special character)

/\r/

with new line (\r)

g

And do it globally (not just the first occurrence on the line).

Community
  • 1
  • 1
LeopardSkinPillBoxHat
  • 28,915
  • 15
  • 75
  • 111
427

On Linux and Mac OS, the following works,

:%s/^V^M/^V^M/g

where ^V^M means type Ctrl+V, then Ctrl+M.

Note: on Windows you probably want to use ^Q instead of ^V, since by default ^V is mapped to paste text.

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
Paul Tomblin
  • 179,021
  • 58
  • 319
  • 408
  • 3
    Why did this get a downvote? It works, even when your file is mashed onto one line because it's got the wrong line end. – Paul Tomblin May 01 '09 at 13:12
  • It really works and is exactly what you need when all your text is on one line. – Bart Schuller May 01 '09 at 13:34
  • Shouldn't %s/^V^M/^V^M/g be %s/^V^M//g ? – Adnan May 01 '09 at 14:01
  • 2
    No. My way replaces whatever is the line end in the file with the correct line end. – Paul Tomblin May 01 '09 at 14:21
  • 1
    This doesn't work, at least on Ubuntu. I get the error `E486: Pattern not found: ^V^M`. – jumpnett Nov 27 '12 at 19:27
  • 2
    @jumpnett, you didn't type it right. colon, then percent, then s, then slash, then control v, then control m, then slash, then control v, then control m, then slash, then g, then return. – Paul Tomblin Nov 27 '12 at 21:19
  • 1
    I didn't type it right. It does replace the `^M`'s, but it also adds an extra newline. What I want is `:%s/^V^M//g`, but that's neither here no there, since I didn't ask the question. – jumpnett Nov 27 '12 at 21:35
  • 1
    This is the correct solution if your file appears to have no newlines at all (i.e. it is one long line). If your file appears to have line endings _and_ the ^M character, then this will add an extra line break between every line. – Leo Mar 21 '13 at 15:31
  • @Leo, the question specifically asks to convert ^M to a linebreak, which is what my answer does (unlike the accepted answer, which removes ^M). – Paul Tomblin Mar 21 '13 at 16:02
  • @PaulTomblin yes, you're quite right. Apologies. The problem I had was subtly different - ^M appearing in `git diff` but not in Vim because of conversion when the file is openend. I had to use Jonathan Leffler's answer in combination with both yours and LeopardSkinPillBoxHat's to wrangle the various files. Perhaps I should have asked a new question, but last time I did so for a slight variation I was told it was a dupe! – Leo Mar 22 '13 at 11:27
  • @PaulTomblin -- your answer works for one long line with ^M's in it. If there are lots of lines, each ending with a ^M, then the accepted answer works since those are really carriage-return/line-feed pairs. – LavaSlider Sep 03 '13 at 17:07
  • @LavaSlider, my experience is that it works for any file with any number of lines. – Paul Tomblin Sep 03 '13 at 17:28
  • But if the line ends with "", ":%s/^V^M/^V^M/g" will change it to "", inserting a blank line. Maybe it's different versions of `vim` but I typed in: hello^V^Mhow^V^Mare^V^Myou^V^M[return]hello^V^M[return]how^V^M[return]are^V^M[return]you^V^M[esc] (where [return] is hitting the return/enter key and [esc] is the escape key). Before executing the command the file has 5 lines, the first with "hello^Mhow^Mare^Myou^M", the next four with one word followed by "^M". After ":%s/^V^M/^V^M/g" there are 13 lines, 1 word per line except blank lines at lines 5,7,9,11 & 13 (on a mac). Try it. – LavaSlider Sep 04 '13 at 14:12
  • That's not my experience with real files moved from Windows to Linux or Windows to Mac. – Paul Tomblin Sep 04 '13 at 14:16
  • This one works for me, files from windows, edited on osx, the question is, why this works, it's a bit odd isn't it, replacing with the same character sequence. – O.O Oct 07 '13 at 02:05
  • 7
    This is for a different problem when your file has NO new lines in it, which I'll admit is more common. FYI ^M can be matched by \r – dlamblin Oct 16 '13 at 18:17
  • 12
    This is a deeply mysterious command, but it works for me on a mac. – Eric Walker Dec 19 '13 at 00:23
  • deeply mysterious indeed and works for me on every server I tried it on from redhat, to ubuntu, to os x. – But those new buttons though.. Dec 04 '14 at 20:37
  • Yep! Works on cygwin too. I had a file created on Ubuntu/scp'ed on to Windows/opened with vim under Cygwin. It had one long line with 1660 ^M's in it. Running this command gave: `1660 substitutions on 1 line` and the file now has 1661 lines. Yay! – Kedar Mhaswade Jun 12 '15 at 16:43
  • This is the correct answer and not the one that has been accepted. – Ashesh Jul 20 '15 at 08:13
  • 7
    I found the equivalent `%s/\r/\r/g` worked well on MacVim for a file showing only `^M` at end of lines (one long line in MacVim terms). Clearly \r means different things in the pattern vs replacement parts of this command. – RichVel Sep 12 '15 at 09:55
  • This works like charm! on OSX+vim. :) Thank you so much. Highly annoying to have ^M in file. – Death Metal Sep 01 '16 at 18:27
  • Your tip on using ^Q on Windows should get an additional +1000 points! Thanks. – Sabuncu Mar 11 '17 at 22:21
  • This didn't worked for me, but RichVel comment %s/\r/\r/g worked for me. Would love to see an answer who explain why this answer didn't worked, but \r does (and another solutions people put). There are a lot of different solutions to this problem, and don't understand what is happening resolves to try everything until something works. – lcjury May 30 '18 at 15:19
  • @Adnan yes, replacing it with nothing worked for me. – pacoverflow Sep 13 '21 at 08:41
  • The CTRL-Q tip fixed my muscle memory in WSL. I could not figure out why it wasn't working as it always does but it makes sense after you explained it. :) – Mark Sep 29 '22 at 17:53
193

Within vim, look at the file format — DOS or Unix:

:set filetype=unix

:set fileformat=unix

The file will be written back without carriage return (CR, ^M) characters.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • 3
    use :set fileformat=unix For most configurations filetype only changes the syntax type being used. – derGral Jun 21 '11 at 07:55
  • 6
    This fixed the bug I was having... Vim started thinking my UNIX formatted file was windows and newly changed lines were showing ^M in the git diff. – Thomas Hunter II Mar 23 '12 at 03:41
  • Must be system dependent. Today, this one worked. The set command is done within vim, btw. – gbarry Nov 28 '12 at 00:36
  • Small gotcha I found: if Git updates a file in the background (due to a checkout) and you have set this to something other than what Vim guessed when opening the file, Vim does not appear to reconvert when reloading the buffer. You'll end up with a bunch of extraneous characters. You can then use one of the %s/^V^M/.../g approaches above. Which one depends on exactly what formats you're converting to and from. – Leo Mar 21 '13 at 15:35
  • 1
    great!because the fileformat is dos, set it to be unix, and it's ok – zhaozhi Jan 14 '14 at 07:57
  • 4
    This also works on vi BTW, and you can do `set ff=unix` as a little shortcut in the same way `ft` is a shortcut for `filetype` – Posva Aug 12 '15 at 13:34
  • @Posva: Thanks for the abbreviations! – Jonathan Leffler Aug 12 '15 at 14:13
  • I like this solution because I don't have to do what I used to do (a) leave vi, (b) vi -b , (c) :s/^M//. Thanks. – Jeff Holt Mar 01 '17 at 17:41
155

This is the only thing that worked for me:

:e ++ff=dos

Found it at: http://vim.wikia.com/wiki/File_format

Pam
  • 4,060
  • 3
  • 19
  • 17
  • 1
    Worked on windows7 Vim7.4 – schuess Nov 09 '15 at 19:05
  • 30
    `:e ++ff=dos` followed by `:set ff=unix` will convert the endings to a sane format. – Mateen Ulhaq Mar 02 '18 at 02:22
  • Solution's response didn't work for me, only @MateenUlhaq commands helped me. – Edenshaw Jul 26 '18 at 17:05
  • Hmm, I suspect a whole host of Internet protocols must be considered "insane", if only LF line endings are deemed "sane" and it is supposed to be some sort of dichotomy?! ... personally I find the "Unix" way no more legitimate than the "DOS" (and Internet protocol) way. – 0xC0000022L Jan 10 '23 at 17:30
125

A file I had created with BBEdit seen in MacVim was displaying a bunch of ^M line returns instead of regular ones. The following string replace solved the issue:

:%s/\r/\r/g

It's interesting because I'm replacing line breaks with the same character, but I suppose Vim just needs to get a fresh \r to display correctly. I'd be interested to know the underlying mechanics of why this works.

starball
  • 20,030
  • 7
  • 43
  • 238
netpoetica
  • 3,375
  • 4
  • 27
  • 37
  • 1
    There's a tendency for search functions to accept broader rules for recognizing end-of-line sequences. But \r has a specific meaning when it's being written as data. – gbarry Nov 28 '12 at 01:18
  • This worked for me in Windows gVim to sort out a file that had no line breaks, just lots of ^M instead. – flash Jan 30 '14 at 23:06
  • 4
    From all the solutions offered on this page, this was the only pattern that worked for me in removing ^M from a csv file. Using MacVim. – B6431 May 21 '14 at 15:45
  • +1 Worked for me too while SSHing to Ubuntu Trusty from Windows using Mobaterm – Carl Jun 25 '14 at 22:12
  • So, this seemed to replace all of the `\r` characters with `\n` despite specifying `\r` as the replacement. Not complaining, that's exactly what I wanted. Just weird. – donut Oct 02 '14 at 18:04
  • [This answer](http://stackoverflow.com/a/12388814/264745) cleared up for me why the search and replace patterns are the same. I would think that has no effect, but they are interpreted differently in each context - I haven't seen that mentioned yet. Short answer seems to be that "\n was already taken". – dcc310 Dec 20 '16 at 22:13
35

First, use :set ff? to figure out the file format your file is.

I guess it could be unix, then the problem is your file was created with fileformat=dos adding "^M^J" to the line end but read with flieformat=unix only removing the "^J" from the line end, leaving the "^M" there.

Just input :e ++ff=dos in Vim command line to change your file's format from unix to dos. It should solve the problem. If not, :%s/\r//g should help you out.

Sam Chen
  • 1,933
  • 16
  • 24
29

in order to get the ^M character to match I had to visually select it and then use the OS copy to clipboard command to retrieve it. You can test it by doing a search for the character before trying the replace command.

/^M

should select the first bad line

:%s/^M/\r/g

will replace all the errant ^M with carriage returns.

This is as functions in MacVim, which is based on gvim 7.

EDIT:

Having this problem again on my Windows 10 machine, which has Ubuntu for Windows, and I think this is causing fileformat issues for vim. In this case changing the ff to unix, mac, or dos did nothing other than to change the ^M to ^J and back again.

The solution in this case:

:%s/\r$/ /g
:%s/ $//g

The reason I went this route is because I wanted to ensure I was being non-destructive with my file. I could have :%s/\r$//g but that would have deleted the carriage returns right out, and could have had unexpected results. Instead we convert the singular CR character, here a ^M character, into a space, and then remove all spaces at the end of lines (which for me is a desirable result regardless)

Sorry for reviving an old question that has long since been answered, but there seemed to be some confusion afoot and I thought I'd help clear some of that up since this is coming up high in google searches.

Metagrapher
  • 8,602
  • 1
  • 24
  • 31
  • 1
    pressing ctrl-v ctrl-m may work to insert the character, as well, fwiw. but the \r is what inserts the proper carriage return. – Metagrapher Nov 26 '11 at 03:06
  • 1
    This is the RIGHT answer. As said above, use to get the literal ^M inserted in the command. – carlosayam Dec 17 '12 at 04:23
  • 1
    I agree, though I am certain that if that had worked for me at the time of original posting then I wouldn't have posted. ;) – Metagrapher Dec 18 '12 at 21:34
24

None of these worked for me, so I tried this, which worked:

type :%s/

press CTRL-VCTRL-M

type //g

press Enter

So the overall command in Vim shoud look like :%s/^M//g

What this does: :%s (find and replace) /^M/ (that symbol) / (with no chars) g (globally).

d-_-b
  • 21,536
  • 40
  • 150
  • 256
  • Bang on!! Works on Mac. – shamail Oct 10 '17 at 08:42
  • Nice Answer. Just kills the `^M` though, doesn't replace them with newlines (vim linux, ff=dos). YMMV depending on which of [mac,windows,linux] you have and what fileformat is currently set to ( see with `:set ff?`). Were you on a mac? – RGD2 Jul 01 '21 at 07:27
18

^M is retrieved by Ctrl+V and M, so do

s/^M//g
Sagar Jain
  • 7,475
  • 12
  • 47
  • 83
Andrew Sledge
  • 10,163
  • 2
  • 29
  • 30
17

Without needing to use Ctrl: :%s/\r$//

BHarman
  • 572
  • 1
  • 6
  • 15
15

Simple thing that worked for me

dos2unix   filename
Shahzeb Khan
  • 3,582
  • 8
  • 45
  • 79
14

I did this with sed:

sed -i -e 's/\r/\n/g' filename

Freedom_Ben
  • 11,247
  • 10
  • 69
  • 89
  • Are you sure this works? On OSX: `sed -e 's/\r/\n/g' <<< 'over and over'` -> `oven and oven` – Armand Jun 29 '18 at 09:59
  • Yes it works (I use it a lot), but on OSX if you do not have the GNU version of sed installed then it may not work. The version of sed that Apple ships by default is much different (sadly) than the GNU version that ships on all Linux distros. Check out the answer to this question for more help: https://stackoverflow.com/q/30003570/2062384 – Freedom_Ben Jun 29 '18 at 20:07
  • Thanks @Freedom_Ben. So it sounds like this works for GNU `sed` but not BSD `sed` then (as found on OSX). Anyone fixing linebreaks is probably working with a mix of operating systems, so it's useful to be clear about when the answer will work. – Armand Jul 05 '18 at 14:20
10

What about just: :%s/\r//g That totally worked for me.

What this does is just to clean the end of line of all lines, it removes the ^M and that's it.

Tonatiuh
  • 2,205
  • 1
  • 21
  • 22
10

There are many other answers to this question, but still, the following works best for me, as I needed a command line solution:

vim -u NONE -c 'e ++ff=dos' -c 'w ++ff=unix' -c q myfile

Explanation:

  • Without loading any .vimrc files, open myfile
  • Run :e ++ff=dos to force a reload of the entire file as dos line endings.
  • Run :w ++ff=unix to write the file using unix line endings
  • Quit vim
Micah Smith
  • 4,203
  • 22
  • 28
8

Ctrl+M minimizes my window, but Ctrl+Enter actually inserts a ^M character. I also had to be sure not to lift off the Ctrl key between presses.

So the solution for me was:

:%s/<Ctrl-V><Ctrl-Enter>/\r/g

Where <Ctrl-V><Ctrl-Enter> means to press and hold Ctrl, press and release V, press and release Enter, and then release Ctrl.

If you are working on a Windows-generated file

The above solution will add an additional line between existing lines, because there is already an invisible \r after the ^M.

To prevent this, you want to delete the ^M characters without replacing them.

:%s/<Ctrl-V><Ctrl-Enter>//g

Where % means "in this buffer," s means "substitute," / means "(find) the following pattern," <Ctrl-V><Ctrl-Enter> refers to the keys to press to get the ^M character (see above), // means "with nothing" (or, "with the pattern between these two slashes, which is empty"), and g is a flag meaning "globally," as opposed to the first occurrence in a line.

CrannDarach
  • 81
  • 2
  • 3
7

This worked for me:

  1. Set file format to unix (\n line ending)
  2. save the file

So in vim:

:set ff=unix
:w
Mathieu
  • 8,840
  • 7
  • 32
  • 45
Stryker
  • 5,732
  • 1
  • 57
  • 70
7

In my case,

Nothing above worked, I had a CSV file copied to Linux machine from my mac and I used all the above commands but nothing helped but the below one

tr "\015" "\n" < inputfile > outputfile

I had a file in which ^M characters were sandwitched between lines something like below

Audi,A4,35 TFSi Premium,,CAAUA4TP^MB01BNKT6TG,TRO_WBFB_500,Trico,CARS,Audi,A4,35 TFSi Premium,,CAAUA4TP^MB01BNKTG0A,TRO_WB_T500,Trico,
Vishwanath gowda k
  • 1,675
  • 24
  • 26
6

Alternatively, there are open-source utilities called dos2unix and unix2dos available that do this very thing. On a linux system they are probably installed by default; for a windows system you can download them from http://www.bastet.com/ amongst others.

ConcernedOfTunbridgeWells
  • 64,444
  • 15
  • 143
  • 197
5
sed s/^M//g file1.txt > file2.txt

where ^M is typed by simultaneously pressing the 3 keys, ctrl + v + m

Blue Diamond
  • 2,979
  • 4
  • 18
  • 21
4

use dos2unix utility if the file was created on windows, use mac2unix utility if the file was created on mac. :)

Ramesh
  • 406
  • 3
  • 9
4

Use one of these commands:

:%s/\r//g

Or

:%s/\r\(\n\)/\1/g
halfer
  • 19,824
  • 17
  • 99
  • 186
Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
3

In command mode in VIM:

:e ++ff=dos | setl ff=unix | up

e ++ff=dos - force open file in dos format.

setl ff=unix - convert file to unix format.

up - save file only when has been modified.

Victor S.
  • 2,510
  • 3
  • 22
  • 35
2

To save keystrokes, you can avoid typing Ctrl+VCtrl+M by placing this in a mapping. Just open a file containing a ^M character, yank it, and paste it into a line like this in your .vimrc:

nnoremap <Leader>d :%s/^M//g<CR>
agouge
  • 147
  • 1
  • 3
2

This worked for me:

:% s/\r\n/\r
ContextSwitch
  • 2,830
  • 6
  • 35
  • 51
2

To use sed on MacOS, do this:

sed -i.bak $'s/\r//' <filename>

Explanation: The $'STRING' syntax here pertains to the bash shell. Macs don't treat \r as special character. By quoting the command string in $'' you're telling the shell to replace \r with the actual \r character specified in the ANSI-C standard.

Nitin Nain
  • 5,113
  • 1
  • 37
  • 51
1

None of these suggestions were working for me having managed to get a load of ^M line breaks while working with both vim and eclipse. I suspect that I encountered an outside case but in case it helps anyone I did.

:%s/.$//g

And it sorted out my problem

rogermushroom
  • 5,486
  • 4
  • 42
  • 68
  • This will remove ANY character at the end of a line. If you have a line that is not, for some reason, terminated by ^M, then you will remove that character also, and would be unexpected. This should not be the case, but in the event that it is, and you don't know this, then you could sully your file in a very hard to identify way. – Metagrapher Sep 11 '17 at 14:00
1
:g/^M/s// /g

If you type ^M using Shift+6 Caps+M it won't accept.

You need to type ctrl+v ctrl+m.

Shravan Kumar
  • 575
  • 1
  • 4
  • 9
1

^M gives unwanted line breaks. To handle this we can use the sed command as follows:

sed 's/\r//g'
Nic Nilov
  • 5,056
  • 2
  • 22
  • 37
  • idk why this was downvoted to -1... because it uses sed? you can do the same substitution inside vim and it _should_ work – Metagrapher Sep 11 '17 at 13:56
1

Just removeset binary in your .vimrc!

falcucci
  • 319
  • 3
  • 5
1

On Solaris:

:%s/<CTRL+V><CTRL+M>//g

that is:

:%s/^M//g

That means:

  • % = all lines,
  • s = substitute,
  • ^M = what you desire to substitute
  • // = replace with nothing
  • g = globally (not only the first occurrance)
Donato Pirozzi
  • 759
  • 2
  • 10
  • 19
0

I've spent an afternoon struggling with \n ctrl-v 012 (both of which supply me with null). & laboured through this thread until I reached metagrapher's.

\r worked fine for me!

/),/s/),/)\r/g

turned something like this:

blacklist-extra:i386 (0.4.1, 0.4.1+nmu1), libmount1:i386 (2.20.1-5.1, 2.20.1 -5.2), libblkid1:i386 (2.20.1-5.1, 2.20.1-5.2), libapt-pkg4.12:i386 (0.9.7.4 , 0.9.7.5), nmap:i386 (6.00-0.1, 6.00-0.2), libsane-common:i386 (1.0.22-7.3,

into something like this:

26 libwv-1.2-4:i386 (1.2.9-3, automatic)
27 openjdk-6-jre-headless:i386 (6b24-1.11.4-3, automatic)
28 jed:i386 (0.99.19-2.1)

Magic. I am profoundly grateful

j0k
  • 22,600
  • 28
  • 79
  • 90
0

Or instead of using vim you can just fix the line breaks using this command

fromdos <filename.txt>

Hope it helps!

bsmoo
  • 949
  • 4
  • 10
  • 23
0

None of the above worked for me. (substitution on \r, ^M, ctrl-v-ctrl-m ) I used copy and paste to paste my text into a new file.

If you have macros that interfere, you can try :set paste before the paste operation and :set nopaste after.

Cory
  • 748
  • 7
  • 18
0

In vim, use command:

:%s/\r\n/\r/g

Where you want to search and replace:

\r\n

into

\r

and the

/g

is for global

Note that this is the same as the answer by @ContextSwitch but with the gobal flag

markyk
  • 61
  • 3
0

Over a serial console all the vi and sed solutions didn't work for me. I had to:

cat inputfilename | tr -d '\r' > outputfilename
robsn
  • 734
  • 5
  • 18
0

" This function preserves the list of jumps

fun! Dos2unixFunction()
let _s=@/
let l = line(".")
let c = col(".")
try
    set ff=unix
    w!
    "%s/\%x0d$//e
catch /E32:/
    echo "Sorry, the file is not saved."
endtry
let @/=_s
call cursor(l, c)
endfun
com! Dos2Unix keepjumps call Dos2unixFunction()
SergioAraujo
  • 11,069
  • 3
  • 50
  • 40
0

If you can see the control characters but your searches are unable to find them using the other methods, and dos2unix isn't working, here's what worked for me.

Move your cursor to the ^ character and press * to start a search for it. I had to manually add a carriage return after it (i.e., after the M) in order for the search to select what I wanted. Then you can run your substitution command on your current search by just leaving the pattern term empty.

:%s//\r/g

This will replace all of the ^M characters with newlines (\r) and perform it on every line (g=global)

swimfar2
  • 103
  • 8
-1

When in windows, try :%s/<C-Q><C-M>/g

jiangdongzi
  • 383
  • 1
  • 2
  • 10
  • 1
    Can you add some explanation as to why this works, i.e. what are you actually doing with the various parts of that command? – LordWilmore Jan 17 '17 at 13:02
  • 1
    This is [just the same as the top answer](http://stackoverflow.com/a/811208/660921), except that `` is replace with `` because by default the former is mapped to paste text. – Martin Tournoij Jan 17 '17 at 13:44
  • ^M means "0d0d0a", `:%s//g` will change "0d0d0a" to "0d0a" (0d0a means \n\r). I dont know why, but it really works in this way (0d0d0a→0d0a i.e. ^M→\n\r) in my windows7 OS. – jiangdongzi Jan 18 '17 at 09:43