split by content of field (original) (raw)


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


From: Assaf Gordon
Subject: csplit - split by content of field
Date: Wed, 06 Feb 2013 17:09:42 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.4) Gecko/20120510 Icedove/10.0.4

Hello,

Attach is a patch that gives 'csplit' the ability to split files by content of a field. A typical usage is:

## the "@1" pattern means "start a new file when field 1 changes"
$ printf "A\nA\nB\nB\nB\nC\n" | csplit - @1 {*}
$ wc -l xx*
2 xx00
3 xx01
1 xx02
6 total
$ head xx*
==> xx00 <==
A
A

==> xx01 <==
B
B
B

==> xx02 <==
C

This is just a proof of concept, and the pattern specification can be changed (I think "@N" doesn't conflict with any existing pattern).

The same can probably be achieved using other programs (awk comes to mind), but it won't be as simple and clean (with all of csplit's output features).

Let me know if you're willing to consider such addition.

Thanks, -gordon

Attachment: 0001-csplit-split-files-by-field-change.patch
Description: Text Data