行尾更改整个项目的编辑器/应用程序 [英] Line endings change editor/app for the whole project

查看:74
本文介绍了行尾更改整个项目的编辑器/应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含许多扩展的项目.这些扩展使用所有3种行尾类型.但是服务器只能与2配合使用.

我有一个可以更改打开文件中行尾的编辑器,但是我需要一个可以批量转换的应用程序,因为它大约有10000个文件.

有什么想法吗?

谢谢!

解决方案

例如,可以使用文本编辑器 UltraEdit 完成此操作.

  1. 点击替换文件中的菜单搜索.
  2. 输入搜索字符串\r?\n|\r
  3. 输入\r\n作为替换字符串,以在所有文件中将所有行尾转换为DOS/Windows,或者将\n转换为Unix行尾.
  4. 如果尚未选择
  5. 选择列出的文件选项.
  6. 在文件/类型中输入 字符串*.*或仅输入*或仅用于匹配文本文件并排除二进制文件的内容.也可以通过使用*.txt;*.htm?;*.php
  7. 这样的分号来分隔多个文件扩展名.
  8. 使用 ... 按钮选择包含要更改的子目录和文件的父目录.
  9. 单击按钮高级或带有齿轮图标的按钮以打开高级选项.
  10. 选中选项搜索子目录.
  11. 选中选项正则表达式,然后选择正则表达式引擎 Perl .
  12. 如果文本文件以UTF-16小端或UTF-16大端进行编码,请同时选中选项使用编码并选择编码 1200 (UTF-16 LE )或 1201 (UTF-16 BE).对于所有其他编码(例如UTF-8或ANSI),不需要在文件中使用编码选项进行此替换.
  13. 使用按钮全部替换立即运行替换.

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.

  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.

这篇关于行尾更改整个项目的编辑器/应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆