问题描述
我需要一个转换实用程序/脚本,将在 Mac 上生成的 .sql 转储文件转换为在 Windows 上可读的文件.这是我在此处遇到的问题的延续.问题似乎与文本文件中的换行符格式有关,但我找不到进行转换的工具...
I need a conversion utility/script that will convert a .sql dump file generated on Mac to one readable on Windows. This is a continuation of a problem I had here. The issue seems to be with newline formatting in text files, but I can't find a tool to make the conversion...
推荐答案
Windows 使用 回车
+ line feed
换行:
Windows uses carriage return
+ line feed
for newline:
Unix 仅使用 Line feed
作为换行符:
Unix only uses Line feed
for newline:
总而言之,只需将 的每次出现替换为
.
unix2dos
和 dos2unix
在 Mac OSX 上默认不可用.
幸运的是,您可以简单地使用 Perl
或 sed
来完成这项工作:
In conclusion, simply replace every occurence of by
.
Both unix2dos
and dos2unix
are not by default available on Mac OSX.
Fortunately, you can simply use Perl
or sed
to do the job:
sed -e 's/$/
/' inputfile > outputfile # UNIX to DOS (adding CRs)
sed -e 's/
$//' inputfile > outputfile # DOS to UNIX (removing CRs)
perl -pe 's/
|
|
/
/g' inputfile > outputfile # Convert to DOS
perl -pe 's/
|
|
/
/g' inputfile > outputfile # Convert to UNIX
perl -pe 's/
|
|
/
/g' inputfile > outputfile # Convert to old Mac
代码片段来自:http://en.wikipedia.org/wiki/Newline#Conversion_utilities
这篇关于将换行符格式从 Mac 转换为 Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!