我有一个 60GB 的单行文件。
我需要做的就是更改最后一个“,”(文件中的最后一个字符)。
问题是 sed
无法处理它,因为它都在一行中并且无法分配内存。
// file.txt
[0] ...mple12,sample13),(sample21,sample22,sample23),
// desired file.txt
[0] ...mple12,sample13),(sample21,sample22,sample23);
我得到一个错误Couldn't re-allocate memory
最佳答案
在这种情况下,面向流的方法可能会有所帮助。 可以很容易地用 shell 实现:
# First remove last character
head -c -1 < file.txt > file2.txt
# then add new last character ';' to the end
echo -n ";" >> file2.txt
请注意:如果文件末尾有CR,则需要改用'head -c -2'。
一行是:
head -c -1 <file.txt | (cat - ; echo ';') > file2.txt
关于linux - 替换大文件中的最后一个字符(整个文件是一行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57162770/