From owner-freebsd-audit Thu Sep 6 4:57:57 2001 Delivered-To: freebsd-audit@freebsd.org Received: from axl.seasidesoftware.co.za (axl.seasidesoftware.co.za [196.31.7.201]) by hub.freebsd.org (Postfix) with ESMTP id C880D37B403 for ; Thu, 6 Sep 2001 04:57:50 -0700 (PDT) Received: from sheldonh (helo=axl.seasidesoftware.co.za) by axl.seasidesoftware.co.za with local-esmtp (Exim 3.33 #1) id 15exor-000G1W-00 for audit@FreeBSD.org; Thu, 06 Sep 2001 13:59:41 +0200 From: Sheldon Hearn To: audit@FreeBSD.org Subject: mixing -l and -p in split(1) Date: Thu, 06 Sep 2001 13:59:41 +0200 Message-ID: <61597.999777581@axl.seasidesoftware.co.za> Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hi folks, I recently ran into a problem that would have been solved perfectly by split(1) if said utility allowed the -l and -p options to be used in conjunction. The specific problem was the need to split a 4GB SMTP transcript into 4 files of approximately 1GB in size, to be passed as input into SMTP socket connections. The following patch allows -l and -p to be used together to mean Split the input into chunks of no fewer than line_count lines per chunk, but ensure that each chunk begins with a line that matches pattern. If pattern does not appear regularly in the input, chunks may be considerably larger than line_count lines. Obviously, it's pretty easy to shot yourself up the ass with this one, but if you know what you're doing, it's invaluable. Ciao, Sheldon. Index: split.c =================================================================== RCS file: /home/ncvs/src/usr.bin/split/split.c,v retrieving revision 1.7 diff -u -d -r1.7 split.c --- split.c 19 Nov 2000 01:44:20 -0000 1.7 +++ split.c 6 Sep 2001 11:18:02 -0000 @@ -147,7 +147,7 @@ if (*argv != NULL) usage(); - if (pflag && (numlines != 0 || bytecnt != 0)) + if (pflag && bytecnt != 0) usage(); if (numlines == 0) @@ -238,14 +238,17 @@ goto writeit; /* Check if we need to start a new file */ - if (pflag) { + lcnt++; + if (pflag && lcnt >= numlines) { regmatch_t pmatch; pmatch.rm_so = 0; pmatch.rm_eo = len - 1; - if (regexec(&rgx, bfr, 0, &pmatch, REG_STARTEND) == 0) + if (regexec(&rgx, bfr, 0, &pmatch, REG_STARTEND) == 0) { newfile(); - } else if (lcnt++ == numlines) { + lcnt = 1; + } + } else if (!pflag && lcnt == numlines) { newfile(); lcnt = 1; } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message