问题
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.
- 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.
来源:https://stackoverflow.com/questions/19859491/line-endings-change-editor-app-for-the-whole-project