转换行尾 [英] Convert line endings
问题描述
我一直使用 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 withd2u
, butdos2unix
. 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 POSIXPOSIX Awk does support
\r
and\15
, however the-i inplace
option is not POSIXd2u 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屋!