我有一个 4000 万行、3 GB 的大文本文件(可能无法放入内存),格式如下:
399.4540176 {Some other data}
404.498759292 {Some other data}
408.362737492 {Some other data}
412.832976111 {Some other data}
415.70665675 {Some other data}
419.586515381 {Some other data}
427.316825959 {Some other data}
.......
每行以一个数字开头,然后是一些其他数据。数字按排序顺序排列。我需要能够:
- 给定一个数字
x和一个范围y,找出所有数字在y范围内的行x。例如 ifx=20和y=5,我需要找到编号在15and之间的所有行25。 - 将这些行存储到另一个单独的文件中。
什么是一种有效的方法来做到这一点而不必遍历整个文件?