将换行格式从 Mac 转换为 Windows [英] Converting newline formatting from Mac to Windows

查看:18
本文介绍了将换行格式从 Mac 转换为 Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个转换实用程序/脚本,它将在 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使用回车 + 换行换行:

Windows uses carriage return + line feed for newline:



Unix 只使用 换行 换行:

Unix only uses Line feed for newline:



总之,只需用 替换每次出现的 .
unix2dosdos2unix 在 Mac OSX 上默认不可用.
幸运的是,您可以简单地使用 Perlsed 来完成这项工作:

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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