ale*_*eit 33 linux windows unix
如何在 Windows 和 Unix/Linux 格式之间转换文本文件中的换行符?
我有一个 *nix 环境,但我需要使用 Windows 样式的换行符导入和导出数据。我以为会有一个标准的实用程序或命令来执行此操作,但我似乎找不到它。
sas*_*ont 42
你可能寻找dos2unix
,unix2dos
,todos
或fromdos
根据您的分布。Ubuntu/Debian 包todos
/fromdos
作为tofrodos包的一部分来自内存。
Che*_*ion 24
一种选择是在命令行上使用unix2dos
(并dos2unix
返回)。
另一种是使用文本编辑器:
对于 vi::set ff=dos 将行尾设置为 dos 行尾。
对于 emacs: Cx [ENTER] f dos [ENTER]
对于您最喜欢的基于 GUI 的编辑器(例如 jedit),我建议您查看手册或谷歌。
最后,如果您不想使用文本编辑器,而只是使用更常见的实用程序等(或没有安装 unix2dos):
tr -d '\r' < infile > outfile
从 Windows -> Unix
awk 'sub("$", "\r")' unixfile.txt > winfile.txt
从 Unix -> Windows 因为tr
不能从 Unix 到 Windows。
ned*_*edm 13
在 Vim 中编辑它并使用set fileformat
命令。
MS-DOS/Windows(CR+LF 中断)到 *nix(仅 LF 中断)
:set fileformat=unix
:wq
Run Code Online (Sandbox Code Playgroud)*nix 到 MS-DOS/Windows
:set fileformat=dos
:wq
Run Code Online (Sandbox Code Playgroud)这是我使用的,类似于 Chealion,将 Windows 转换为 Unix 行尾:
tr -d \\015 < windows > unix
Run Code Online (Sandbox Code Playgroud)