[英]Change EOL on multiple files in one go
Is there any way in Notepad++ (or even with another tool) to change the line ending automatically on multiple files in one go ? Notepad++(或什至使用其他工具)是否有任何方法可以一次性更改多个文件自动结束的行?
ie convert a mix of windows EOL ( CRLF
) and UNIX EOL ( LF
) files to be all Windows EOL ( CRLF
)即将 Windows EOL (
CRLF
) 和 UNIX EOL ( LF
) 文件的混合转换为所有 Windows EOL ( CRLF
)
The Replace dialog can handle extended characters like EOL.替换对话框可以处理扩展字符,如 EOL。 Just change "Search Mode" to "Extended", and you can work with EOL (\r\n in Windows or \n in Unix), tabs (\t), etc.
只需将“搜索模式”更改为“扩展”,您就可以使用 EOL(Windows 中的 \r\n 或 Unix 中的 \n)、制表符 (\t) 等。
You can also use the Find in Files tab of the dialog to do the replace across multiple files.您还可以使用对话框的“在文件中查找”选项卡跨多个文件进行替换。
I have Notepad++ 6.1.2.我有记事本++ 6.1.2。
In "Edit" menu you have "EOL conversion" that does exactly what you need.在“编辑”菜单中,您有“EOL 转换”可以完全满足您的需要。
Use the 'Find In Files' feature (Ctrl + Shift + F).使用“在文件中查找”功能(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.它所做的是用 \r\n 替换当前前面没有回车符 (\r) 的任何换行符 (\n)。 So it won't match line endings that are already Windows style.
所以它不会匹配已经是 Windows 样式的行结尾。
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).这会将所有可能的行结束模式(单个 \r、\n 或 \r\n)匹配回 \r\n (Windows)。
To operate on multiple files, either:要对多个文件进行操作,可以:
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.
您还可以通过“设置”->“首选项”->“新建文档/默认目录”在记事本++中设置默认 EOL,然后在格式框下选择“Unix/OSX”。
Note: One can always use an out-of-band option using the command line:注意:始终可以使用命令行使用带外选项:
unix2dos *.cmd
dos2unix *.sh
To convert multiple files into one directory and recursively.将多个文件递归地转换到一个目录中。 Just install PythonScript on Notepad ++, then use the script below
只需在Notepad++上安装PythonScript,然后使用下面的脚本
https://gist.github.com/bjverde/583c2ee8b386994f3a1f8acdea3b7ed2 https://gist.github.com/bjverde/583c2ee8b386994f3a1f8acdea3b7ed2
This did the work for me这对我有用
git config core.autocrlf false
git rm --cached -r .
git reset --hard
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.