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

查看:209
本文介绍了将换行格式从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使用回车 + 换行符换行:

\r\n

换行符换行符:

Unix only uses Line feed for newline:

\n

总之,只需将 \\\
code> \r\\\


unix2dos dos2unix 在Mac OSX上不是默认可用。

幸运的是,您可以简单地使用 Perl sed 做这个工作:

In conclusion, simply replace every occurence of \n by \r\n.
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/$/\r/' inputfile > outputfile                # UNIX to DOS  (adding CRs)
sed -e 's/\r$//' inputfile > outputfile                # DOS  to UNIX (removing CRs)
perl -pe 's/\r\n|\n|\r/\r\n/g' inputfile > outputfile  # Convert to DOS
perl -pe 's/\r\n|\n|\r/\n/g'   inputfile > outputfile  # Convert to UNIX
perl -pe 's/\r\n|\n|\r/\r/g'   inputfile > outputfile  # Convert to old Mac

代码片段来自:
http://en.wikipedia.org/wiki/Newline#Conversion_utilities

这篇关于将换行格式从Mac转换到Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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