转换行尾 [英] Convert line endings

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

问题描述

我一直使用 d2u 来转换行尾。安装Puppy Linux后,I
注意到它不是 d2u ,而是 dos2unix 。然后我注意到,
Ubuntu默认情况下都丢失了。



另一种方法是转换行尾吗?

解决方案

使用POSIX做这件事很麻烦:




  • POSIX Sed 不支持 \r \15 。即使是,
    选项 -i 不是POSIX


  • a href =http://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html =nofollow noreferrer> POSIX Awk 支持 \r \15 ,但 -i inplace 选项
    不是POSIX


  • d2u dos2unix 不是 POSIX实用程序,但


  • POSIX ex 不支持 \r \15 \\\
    \12




要移除回车符:

  ex -bsc'%!awk{sub(/ \r /,\\)} 1'-cx file 

要添加回车符:

  ex -bsc'%!awk{sub(/ $ /,\\r\)} 1'-cx文件
/ pre>

I have been using d2u to convert line endings. After installing Puppy Linux I noticed that it does not come with d2u, but dos2unix. Then I noticed that Ubuntu is missing both by default.

What is another way to convert line endings?

解决方案

Doing this with POSIX is tricky:

  • POSIX Sed does not support \r or \15. Even if it did, the in place option -i is not POSIX

  • POSIX Awk does support \r and \15, however the -i inplace option is not POSIX

  • d2u and dos2unix are not POSIX utilities, but ex is

  • POSIX ex does not support \r, \15, \n or \12

To remove carriage returns:

ex -bsc '%!awk "{sub(/\r/,\"\")}1"' -cx file

To add carriage returns:

ex -bsc '%!awk "{sub(/$/,\"\r\")}1"' -cx file

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

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