Thursday, February 23, 2017

Split a Text File using csplit

Suppose you have a large "sectioned" text file which looks like the following

> cat bigfile.txt
data1
1
2
3

data2
11
22
33

...

csplit bigfile.txt /data/ {*}

splits it into a bunch of files xx0, xx1, xx2, ..., where each of the "xx" files holds a section. Thus,

> cat xx1
data1
1
2
3

and so on. Can be just the quick tool you need at times.

No comments: