开发者

Sed script command truncating last line

I'm trying to remove the carriage returns (\r) from a file开发者_如何学C 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.


You can also use dos2unix if you have it in AIX, however, with sed,

sed '$!{:a;N;s/\r\n/\n/;ta}' file

sed strips off the newline whenever it process current line (see the man page), so you won't really find the \r\n.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜