Skip to main content

x2y:在 DOS、Mac 和 Unix 之间转换行尾

项目描述

在 DOS、Mac(OS X 之前)和 Unix 之间转换行尾

在哪里:

  • DOS = '\r\n'

  • Mac = '\r' (OS9)

  • Unix = '\n'

注意:这里的 Mac 是 OS9 及更早版本。OS X 行尾是 Unix。

例子

从 Unix 转换为 DOS 行尾

$ x2y -f unx -t dos file.txt

上面的命令会将 Unix 行结束符转换为 DOS 行结束符。结果被写回源文件。

如果要写入另一个文件,请使用 -o 或 -d 选项(见下文)。

$ x2y -o output.txt -f unx -t dos file.txt

将转换后的文件写入 output.txt

$ x2y -d outputs -f unx -t dos file.txt

将转换后的文件保存到输出目录。

要备份源文件,请使用 -b 选项。例如:

$ x2y -b bak -f unx -t dos file.txt

在写入转换后的文件之前,将使用“.bak”扩展名重命名源文件。

安装

pip install x2y

用法

usage: x2y [options] --from line-ending --to line-ending File [File ...]

x2y: convert line ending between DOS, Mac (pre OS X) and Unix

positional arguments:
  File                  Files to convert

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --debug               Turn on debug logging.
  --debug-log FILE      Save debug logging to FILE.
  -b BACKUP EXTENTSION, --backup BACKUP EXTENTSION
                        Save a backup of the input file by renaming with
                        BACKUP EXTENTSION. Ignored if the -o option is given.
                        Default: None.
  -d DIRECTORY, --directory DIRECTORY
                        Save extracted text to DIRECTORY. Ignored if the -o
                        option is given.
  -f {dos,mac,unx}, --from {dos,mac,unx}
                        Line ending to convert from.
  -o FILE, --output FILE
                        Save extracted text to FILE. If not given, the output
                        file is named the same as the input file but with a
                        txt extension. The extension can be changed with the
                        -e option. Files are opened in append mode unless the
                        -X option is given.
  -t {dos,mac,unx}, --to {dos,mac,unx}
                        Line ending to convert to.
  -A, --suppress-file-access-errors
                        Do not print file/directory access errors.

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

x2y-0.1.0.tar.gz (9.3 kB 查看哈希

已上传 source

内置分布

x2y-0.1.0-py2.py3-none-any.whl (8.3 kB 查看哈希

已上传 py2 py3