Line endings change editor/app for the whole project

做~自己de王妃 提交于 2019-12-20 03:54:15

问题


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!


回答1:


This can be done for example with text editor UltraEdit.

  1. Click in menu Search on Replace in Files.
  2. Enter as search string \r?\n|\r
  3. 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.
  4. Select Files Listed option if not already selected.
  5. 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
  6. Select with the button ... the parent directory containing the subdirectories and files to change.
  7. Click on button Advanced or the button with the gearwheel icon to open the advanced options.
  8. Check the option Search subdirectories.
  9. Check the option Regular expressions and select the regular expression engine Perl.
  10. 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.
  11. 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.



来源:https://stackoverflow.com/questions/19859491/line-endings-change-editor-app-for-the-whole-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!