JSON file often only in 1 line.
To remove first n character:
sed -i.bak -r '1s/^.{10}//' file
https://stackoverflow.com/questions/26400118/delete-first-n-characters-of-a-very-large-file-in-unix-shell
See first 50 bytes of file:
head -c 50 file
See last 50 bytes:
tail -c 50 file
remove last n character
sed '$ s/.$//' somefile # slow and not work, don't know why
truncate -s-1 file # super fast
https://stackoverflow.com/questions/27305177/how-can-i-remove-the-last-character-of-a-file-in-unix
I use git-bash windows 10, JSON ab 3GB
Why not sed
The problem with a sed solution like sed '$ s/.$//' file is that it reads the whole file first (taking a long time with large files), then you need a temporary file (of the same size as the original):
One more time my psychological knowledge suck. The "right" answer here is not marked right, OK but it seem better.
To remove first n character:
sed -i.bak -r '1s/^.{10}//' file
https://stackoverflow.com/questions/26400118/delete-first-n-characters-of-a-very-large-file-in-unix-shell
See first 50 bytes of file:
head -c 50 file
See last 50 bytes:
tail -c 50 file
remove last n character
sed '$ s/.$//' somefile # slow and not work, don't know why
truncate -s-1 file # super fast
https://stackoverflow.com/questions/27305177/how-can-i-remove-the-last-character-of-a-file-in-unix
I use git-bash windows 10, JSON ab 3GB
Why not sed
The problem with a sed solution like sed '$ s/.$//' file is that it reads the whole file first (taking a long time with large files), then you need a temporary file (of the same size as the original):
One more time my psychological knowledge suck. The "right" answer here is not marked right, OK but it seem better.
Comments
Post a Comment