Sed 脚本命令截断最后一行
我试图在 AIX 上使用以下命令从文件中删除回车符 (\r
),但它也会删除我的最后一行。有什么建议吗?
sed -e 's/\r\n/\n/g' ./excprule > ./excprule.tst
命令序列:
dev1:> sed -e 's/\r\n/\n/g' ./test_file > ./test_file.tst dev1:> diff test_file.tst test_file diff: 0653-827 Missing newline at the end of file test_file. 26a27 > Trailer 25
编辑:通过使用 perl 执行相同的操作找到了解决方法,但想知道为什么这不起作用。
I'm trying to remove the carriage returns (\r
) from a file with the following command on AIX, but it's also removing my last line. Any suggestions?
sed -e 's/\r\n/\n/g' ./excprule > ./excprule.tst
Command sequence:
dev1:> sed -e 's/\r\n/\n/g' ./test_file > ./test_file.tst dev1:> diff test_file.tst test_file diff: 0653-827 Missing newline at the end of file test_file. 26a27 > Trailer 25
Edit: Found a workaround by doing the same thing with perl, but would like to know why this doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 AIX 中有 dos2unix,您也可以使用 dos2unix,但是,使用 sed,
sed 在处理当前行时会去掉换行符(请参阅手册页),因此您不会真正找到
\r\n< /代码>。
You can also use dos2unix if you have it in AIX, however, with sed,
sed strips off the newline whenever it process current line (see the man page), so you won't really find the
\r\n
.