Cut text file in place

I have a file that i want to take only the first part of it and discard the rest, to be accurate,I need the first 137097 lines but I cant use split because I dont have enough space on my disck. I need sth to cut the file in its place

for GNU sed, try:

sed -i -e '1,137097!d' infile
1 Like

That will still have to store its temp file somewhere, before replacing the original file.

In general, 'in place' almost never is, because files do not work that way. You cannot tell a disk 'snip this line here, change that text there, and make it all line up properly'. You get to seek, overwrite, and truncate, and that's it.

And that is what you need to do here -- truncate. Figure out exactly what byte you need the file to stop at, seek to that point, then truncate the rest. What languages can you use? I'm not sure you can do this in pure shell.