AIX:从文件中删除最后一个符号(CRLF) [英] AIX: remove the last symbols (CRLF) from a file
问题描述
有一个大文件,最后一个符号为 \r\n
。我需要删除它们。它似乎等效于删除最后一行(?)。
UPD :不,不是:文件只有一行,以 \r\n
结尾。 p>
我知道两种方法,但两种方法都不适用于AIX:
sed's / \r\n $ //'文件#我不知道为什么它不起作用
head -c-2#head不能与负数
AIX是否有解决方案?
我的回答https://stackoverflow.com/a/46083912/3220113 到重复的问题也应该在这里起作用。另一个解决方案是使用
awk'(NR> 1){print s}
{s = $ 0}
END {printf(%s,substr($ 2,1,length($ 2)-1))}
'输入文件
There is a large file where the last symbols are \r\n
. I need to remove them. It seems to be equivalent to removing the last line(?).
UPD: no, it's not: a file have only one line, which ends with \r\n
.
I know two ways, but both don't work for AIX:
sed 's/\r\n$//' file # I don't why it doesn't work
head -c-2 # head doesn't work with negative numbers
Is there any solution for AIX? A lot of large files must be processed, so performance is important.
My answer https://stackoverflow.com/a/46083912/3220113 to the duplicate question should work here too. Another solution is using
awk ' (NR>1) { print s }
{s=$0}
END { printf("%s",substr($2, 1, length($2)-1) ) }
' inputfile
这篇关于AIX:从文件中删除最后一个符号(CRLF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!