行尾更改整个项目的编辑器/应用程序 [英] Line endings change editor/app for the whole project
问题描述
我有一个包含许多扩展的项目.这些扩展使用所有3种行尾类型.但是服务器只能与2配合使用.
我有一个可以更改打开文件中行尾的编辑器,但是我需要一个可以批量转换的应用程序,因为它大约有10000个文件.
有什么想法吗?
谢谢!
例如,可以使用文本编辑器 UltraEdit 完成此操作.
- 点击替换文件中的菜单搜索.
- 输入搜索字符串
\r?\n|\r
- 输入
\r\n
作为替换字符串,以在所有文件中将所有行尾转换为DOS/Windows,或者将\n
转换为Unix行尾.
如果尚未选择 - 选择列出的文件选项.
- 在文件/类型中输入 字符串
*.*
或仅输入*
或仅用于匹配文本文件并排除二进制文件的内容.也可以通过使用*.txt;*.htm?;*.php
这样的分号来分隔多个文件扩展名.
- 使用 ... 按钮选择包含要更改的子目录和文件的父目录.
- 单击按钮高级或带有齿轮图标的按钮以打开高级选项.
- 选中选项搜索子目录.
- 选中选项正则表达式,然后选择正则表达式引擎 Perl .
- 如果文本文件以UTF-16小端或UTF-16大端进行编码,请同时选中选项使用编码并选择编码 1200 (UTF-16 LE )或 1201 (UTF-16 BE).对于所有其他编码(例如UTF-8或ANSI),不需要在文件中使用编码选项进行此替换.
- 使用按钮全部替换立即运行替换.
Perl正则表达式搜索字符串\r?\n|\r
与回车符和换行符对(CRLF-DOS/Windows)匹配,或者仅与换行符(LF-Unix)匹配,或者仅与回车符(CR-Mac)匹配. /p>
运行该Perl正则表达式Replace All后,所有匹配文件的修改日期都将更改,因为搜索表达式会找到所有3种行尾类型.
但是也可以通过使用搜索字符串\r\n|\r
和\n
作为替换字符串将仅所有DOS/Mac文件转换为Unix.使用此搜索表达式不会修改仅包含换行符的文件,因此已经是Unix文件.
使用(?<!\r)\n|\r(?!\n)
作为搜索字符串,使用\r\n
作为替换字符串,仅将所有Unix/Mac文件转换为DOS/Windows.此搜索表达式不会修改仅包含\r\n
的文件.
I have a project composed of many extensions. And these extensions use all 3 line ending types. But the server can work only with 2.
I have an editor that can change line endings in opened file but I need to get some app that can do a batch conversion because it is about 10 000 files.
Any ideas?
Thank you!
This can be done for example with text editor UltraEdit.
- Click in menu Search on Replace in Files.
- Enter as search string
\r?\n|\r
- Enter as replace string either
\r\n
to convert in all files all line endings to DOS/Windows or just\n
for Unix line endings. - Select Files Listed option if not already selected.
- Enter for In files/types the string
*.*
or just*
or whatever is suitable to match only text files and exclude binary files. Multiple file extensions can be also specified by separating them with a semicolon like*.txt;*.htm?;*.php
- Select with the button ... the parent directory containing the subdirectories and files to change.
- Click on button Advanced or the button with the gearwheel icon to open the advanced options.
- Check the option Search subdirectories.
- Check the option Regular expressions and select the regular expression engine Perl.
- If the text files are encoded in UTF-16 little endian or UTF-16 big endian, check also option Use encoding and select encoding 1200 (UTF-16 LE) or 1201 (UTF-16 BE). For all other encodings like UTF-8 or ANSI the encoding option does not need to be used for this replace in files.
- Run the replace now with button Replace all.
The Perl regular expression search string \r?\n|\r
matches either a carriage return and linefeed pair (CRLF - DOS/Windows), or just a linefeed (LF - Unix), or just a carriage return (CR - Mac).
All matching files will have a new modification date after running that Perl regular expression Replace All because the search expression finds all 3 line ending types.
But it is also possible to convert only all DOS/Mac files to Unix by using as search string \r\n|\r
and \n
as replace string. The files containing only linefeeds and therefore being already Unix files are not modified by using this search expression.
Use (?<!\r)\n|\r(?!\n)
as search string and \r\n
as replace string to convert only all Unix/Mac files to DOS/Windows. Files containing already only \r\n
are not modified by this search expression.
这篇关于行尾更改整个项目的编辑器/应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!