I have several big files (ranging from 1GB to 1TB) and I want to remove the first and last character in each.
What's a fast way to do it (preferably with a simple bash script)? I don't need to save the old file.
I have several big files (ranging from 1GB to 1TB) and I want to remove the first and last character in each.
What's a fast way to do it (preferably with a simple bash script)? I don't need to save the old file.
There is no fast way to do it in a shell.
head -c -1 < in.txt | tail -c +1 > out.txt
If you don't mind dropping to C, calling sendfile(2)
with a *offset
of 1 and a count
of the size less 2 will likely be the fastest possible way.
To quickly truncate the last character of a file you can use:
truncate -s-1 file
This will modify the file directly and avoid creating a copy of your large file. This asks truncate to reduce the size of the file by 1 . See original answer: https://stackoverflow.com/a/40568723