我有一个包含以下几行的文件:
1291126929200 started 88 videolist15.txt 4 Good 4
1291126929250 59.875 29.0 29.580243595150186 43.016096916037604
1291126929296 59.921 29.0 29.52749417740926 42.78632483544682
1291126929359 59.984 29.0 29.479540161281143 42.56031951027556
1291126929437 60.046 50.0 31.345036510255586 42.682281485516945
1291126932859 started 88 videolist15.txt 5 Good 4
我想为包含
started
(或videolist
,无所谓)的每一行拆分文件。以下命令仅生成2个输出文件:
$ csplit -k input.txt /started/
但是,我期望有更多,如下所示:
$ grep -i started input.txt |wc -l
$ 146
什么是正确的
csplit
命令?谢谢
最佳答案
只需在末尾添加{*}
即可:
$ csplit -k input.txt /started/ {*}
手册页显示:
{*} repeat the previous pattern as many times as possible.
演示:
$ cat file
1
foo
2
foo
3
foo
$ csplit -k file /foo/ {*}
2
6
6
4
$ ls -tr xx*
xx03 xx02 xx01 xx00
$ csplit --version
csplit (GNU coreutils) 7.4
关于regex - 为csplit寻找正确的正则表达式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4323703/