按行号矢量分割文件 [英] Split file by vector of line numbers
本文介绍了按行号矢量分割文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个大文件,大约10GB.我有一个行号向量,我想用它来分割文件.理想情况下,我想使用命令行实用程序来完成此操作.作为正则表达式:
I have a large file, about 10GB. I have a vector of line numbers which I would like to use to split the file. Ideally I would like to accomplish this using command-line utilities. As a regex:
文件:
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
16 17 18
行号向量:
2 5
所需的输出:
文件1:
1 2 3
文件2:
4 5 6
7 8 9
10 11 12
文件3:
13 14 15
16 17 18
推荐答案
这可能对您有用:
csplit -z file 2 5
或者如果您想使用正则表达式:
or if you want regexp:
csplit -z file /2/ /5/
使用默认值,输出文件将被命名为 xxnn
,其中 nn
从 00
开始并以1递增.
With the default values, the output files will be named xxnn
where nn
starts at 00
and is incremented by 1.
-z
选项可防止清空文件.
这篇关于按行号矢量分割文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文