Change EOL on multiple files in one go
Asked Answered
P

8

111

Is there any way in Notepad++ (or even with another tool) to change the line ending automatically on multiple files in one go?

i.e. convert a mix of windows EOL (CRLF) and UNIX EOL (LF) files to be all Windows EOL (CRLF)

Pell answered 5/7, 2012 at 9:38 Comment(1)
In case notepad++ isn't a firm requirement, the info here might be relevant: #3110531Soto
O
115

The Replace dialog can handle extended characters like EOL. Just change "Search Mode" to "Extended", and you can work with EOL (\r\n in Windows or \n in Unix), tabs (\t), etc.

You can also use the Find in Files tab of the dialog to do the replace across multiple files.

Screenshot

Overexcite answered 5/7, 2012 at 9:46 Comment(7)
Note that this solution will not work if all your files are not already unix-style. Since replacing \n with \r\n will also convert \r\n to \r\r\n.Lynnlynna
-1 without changing Edit>EOL conversion (see Dos\Windows in the status bar of your screenshot), pressing ENTER will insert the wrong EOL - and having mixed EOL is even worse than keeping to any of the standardsGlobule
replace \n with \r\n. then replace \r\r\n with \r\n. voila!Hopple
Why your screenshot example shows \t in Find what? Tabs have nothing to do with changing line endings, right?Metabolic
Great tip! This helped me convert Windows line endings to Unix style in a pile of files where I wanted to also see which ones had the wrong endings (rather than using a tool to do this on everything automatically).Antetype
great...it works perfectly in notepad++ editor...it saves huge effort, that we are going to spend by manual changesPretender
files are too large. but this worked on 3-4 of the 30 something I have left.Creuse
G
94

I have Notepad++ 6.1.2.
In "Edit" menu you have "EOL conversion" that does exactly what you need.

Goyette answered 5/7, 2012 at 9:42 Comment(12)
that works on a file basis, cannot be applied to a whole set of files.Pell
Have you read the title of the question? Did you see the "change EOL on multiple files" part?Helban
@Sk8erPeter: if you take a look at the question, you can see its title has been edited after my question was posted...Goyette
@Marco: NO, that's not true. I looked at the revision thread before commenting, and as you can see, the ORIGINAL title AND body of the question also contained "on multiple files": i.imgur.com/kSYdJA9.png...Helban
@Sk8erPeter: but not "in one go" :DGoyette
@Marco: oh yeah, but unfortunately it doesn't change the fact that you didn't answer the question, you just wrote down how to change EOL for one single file... :DHelban
You would open more than one file to do it to more than one file, sequentially. Like he said, "in one go" wasn't originally there.Roque
In fact the answer was very useful to me, since I needed to change EOL in single files, and I didn't know how.Acidophil
Useful answer as this comes up first in GoogleFabyola
I'm sorry but don't you guys read the question? "in one go" was originally in the question as also the example given by the OP. I assume that for answering a question, you have to actually read the question, not only the title. Builtin "EOL conversion" feature is largely known, but how to reliable convert a set of files is a bit hard to find.Landman
This is a completely incorrect answer to the question. The "in one go" part wasn't added in with an edit, it was there in the original postGemsbok
Yes, useful answer... to a different questionEnthetic
C
84

Use the 'Find In Files' feature (Ctrl + Shift + F). Change the search mode at the bottom left to 'Regular Expression'.

In the 'Find what' box, use this pattern:

(?<!\r)\n

Replace with:

\r\n

Choose your directory and specify any file type filters. Check 'In all sub-folders' if you want. Click 'Replace in Files'.

What this does is replace any newline characters (\n) that are not currently preceded by a carriage return (\r) with \r\n. So it won't match line endings that are already Windows style.

enter image description here

Collapse answered 3/8, 2014 at 21:28 Comment(5)
Could you explain what (?<!\r)\n means, especially the first ?<! part, thanks!Dira
the (?<! ) is a negative lookbehind. It means match if prefix is absent. In this case it's checking for \r and will only match if \n doesnt have an \r before it.Bespangle
Yep. I agree with rtpHarry. This is this part from my answer: "any newline characters (\n) that are not currently preceded by a carriage return (\r)".Collapse
most sophisticated solution!Gallup
Technically speaking, this is the most precise and complete answer on this page.Reese
J
15

Use replace all with regular expression

(\r?\n)|(\r\n?)

to

\r\n

This will match every possible line ending pattern (single \r, \n or \r\n) back to \r\n (Windows).

To operate on multiple files, either:

  • Use "Replace All in all opened document" in "Replace" tab. You will have to drag and drop all files into Notepad++ first. It's good that you will have control over which file to operate on but can be slow if there several hundreds or thousands files.
  • "Replace in files" in "Find in files" tab, by file filter of you choice, e.g., *.cpp *.cs under one specified directory.
Jurkoic answered 24/7, 2015 at 3:28 Comment(2)
Best answer, as it works with all flavours of line endings. Thanks!Cropland
This is the best and easiest answer!Club
B
7

The only WORKING solution i found for multiple files/folders, after googling for 1 hour is this:

  • install PyCham trial mode,
  • open and select your Project Folder/Folders and follow the screenshot

enter image description here

Banna answered 5/2, 2018 at 10:21 Comment(2)
Also works in IntelliJ IDEA Community Edition, which is free and does not require trial. IntelliJ IDEA.Colner
Pity for the downvote. I came here as I thought that "Rider (PyCharm for C#) won't do that, let's start with notepad++". Thanks.Foursquare
A
1

Found this solution via this discussion:

You can also set the default EOL in notepad++ via "Settings" -> "Preferences" -> "New Document/Default Directory" then select "Unix/OSX" under the Format box.

Note: One can always use an out-of-band option using the command line:

unix2dos *.cmd
dos2unix *.sh
Arachnoid answered 3/3, 2018 at 16:32 Comment(0)
P
1

To convert multiple files into one directory and recursively. Just install PythonScript on Notepad ++, then use the script below

https://gist.github.com/bjverde/583c2ee8b386994f3a1f8acdea3b7ed2

Phonsa answered 7/6, 2020 at 22:2 Comment(0)
W
1

This did the work for me

git config core.autocrlf false 
git rm --cached -r . 
git reset --hard
Willywillynilly answered 2/5, 2022 at 9:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.