I have a big file around 60GB.
I need to get n middle lines of the file. I am using a command with head and tail like
tail -m file |head -n >output.txt
where m,n are numbers
The general structure of the file is like below with set of records (comma separated columns.) Each line can be of different length(say max 5000 chars).
col1,col2,col3,col4...col10
Is there any other way that I can take n middle lines with less time, because the current command is taking lot of time to execute?
The only possible solution I can think of to speed up the search is to build and index of your lines, something like:
And then, knowing the index length, you could jump quickly in the middle of your data file (or wherever you like...). Of course you should keep the index updated when the file changes...
Obviously the canonical solution for such a problem would be to keep the data in a DB (see for example SQLite), an not in a plain file... :-)