[Toybox] [PATCH] A implemetation of the 'csplit' command
Oliver Webb
aquahobbyist at proton.me
Wed Sep 13 18:20:52 PDT 2023
Sent with Proton Mail secure email.
------- Original Message -------
On Wednesday, September 13th, 2023 at 12:56 AM, Rob Landley <rob at landley.net> wrote:
> On 9/12/23 23:43, Oliver Webb wrote:
>
> > ------- Original Message -------
> > On Tuesday, September 12th, 2023 at 2:36 PM, Rob Landley rob at landley.net wrote:
> >
> > > On 9/11/23 23:56, Oliver Webb via Toybox wrote:
> > >
> > > > I have made a implementation of the 'csplit' command in about 160 lines of code.
>
>
> By the way, have you found anything that actually uses this? Busybox hasn't
> bothered to implement it, and line selection is a trivial function of sed,
> including regex support:
The main reason I wrote this command is because it was in POSIX and the roadmap of the project,
but for actual use cases it has a clearer syntax then sed does when specifying rules for splitting files.
One of the things I fixed in this patch is that it doesn't reset the line number
every time it encounters "{NUMBER}" rules. And can do stuff like "/foobar/ {4} 321" correctly now.
$ yes a | head -n 8 | ./csplit - /a/ {3} 7 -s; wc -l xx0*
0 xx00
1 xx01
1 xx02
1 xx03
3 xx04
2 xx05
8 total
This will probably be my last patch to the csplit command for a while.
I have everything except negative offsets working properly. I fixed some issues with the
way the command breaks at line numbers. As well as adjusted some of the formatting for the code.
And the tracking of file sizes works by a "filesize += strlen(line);" in the main loop instead of
stat()'ing every file after it's written.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 806e53f1.patch
Type: text/x-patch
Size: 4446 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20230914/991fec41/attachment.bin>
More information about the Toybox
mailing list