[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] [cut] Treat consecutive delimiters as one in cut binary
From: |
Joe Maimon |
Subject: |
[PATCH] [cut] Treat consecutive delimiters as one in cut binary |
Date: |
Thu, 04 Mar 2004 22:58:48 -0500 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7a) Gecko/20040219 |
When using the -d option I find it frustrating that arbitrary whitespace
ruins the field count.
witness this script:
dig -x $addr +noall +answer | grep -v '^;' | grep -v '$^' | expand | cut
-d' ' -f5 -z
With the new option in this patch, you can rely on the behavior to
produce a hostname if there is one. Otherwise you cant.
If I am being naive, I apologize.
Thanks,
Joe M
diff -urN coreutils-5.2.0/man/cut.1 coreutils-5.2.0-jm/man/cut.1
--- coreutils-5.2.0/man/cut.1 Sun Feb 8 15:14:24 2004
+++ coreutils-5.2.0-jm/man/cut.1 Fri Feb 20 02:23:40 2004
@@ -35,6 +35,8 @@
\fB\-\-output\-delimiter\fR=\fISTRING\fR
use STRING as the output delimiter
the default is to use the input delimiter
+.HP
+\fB\-z\fR, \fB\-\-squeeze\-delimiters\fR treat consecutive delimiters as one
.TP
\fB\-\-help\fR
display this help and exit
Binary files coreutils-5.2.0/src/.cut.c.swp and
coreutils-5.2.0-jm/src/.cut.c.swp differ
diff -urN coreutils-5.2.0/src/cut.c coreutils-5.2.0-jm/src/cut.c
--- coreutils-5.2.0/src/cut.c Wed Jan 21 17:27:02 2004
+++ coreutils-5.2.0-jm/src/cut.c Fri Feb 20 02:23:35 2004
@@ -129,6 +129,9 @@
/* The delimeter character for field mode. */
static unsigned char delim;
+/* Whether we treat consecutive delimiters as one (squeeze) */
+static unsigned char delim_squeeze = false;
+
/* True if the --output-delimiter=STRING option was specified. */
static bool output_delimiter_specified;
@@ -166,6 +169,7 @@
{"delimiter", required_argument, 0, 'd'},
{"only-delimited", no_argument, 0, 's'},
{"output-delimiter", required_argument, 0, OUTPUT_DELIMITER_OPTION},
+ {"squeeze-delimiters", no_argument, 0, 'z'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{0, 0, 0, 0}
@@ -206,6 +210,9 @@
--output-delimiter=STRING use STRING as the output delimiter\n\
the default is to use the input delimiter\n\
"), stdout);
+ fputs (_("\
+ -z, --squeeze-delimiters treat consecutive delimiters as one\n\
+"), stdout);
fputs (HELP_OPTION_DESCRIPTION, stdout);
fputs (VERSION_OPTION_DESCRIPTION, stdout);
fputs (_("\
@@ -630,6 +637,12 @@
}
found_any_selected_field = true;
+ if (delim_squeeze)
+ {
+ while ((c = getc (stream)) == delim);
+ ungetc (c, stream);
+ }
+
while ((c = getc (stream)) != delim && c != '\n' && c != EOF)
{
putchar (c);
@@ -637,6 +650,12 @@
}
else
{
+ if (delim_squeeze)
+ {
+ while ((c = getc (stream)) == delim);
+ ungetc (c, stream);
+ }
+
while ((c = getc (stream)) != delim && c != '\n' && c != EOF)
{
/* Empty. */
@@ -741,7 +760,7 @@
delim = '\0';
have_read_stdin = false;
- while ((optc = getopt_long (argc, argv, "b:c:d:f:ns", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "b:c:d:f:nsz", longopts, NULL)) !=
-1)
{
switch (optc)
{
@@ -788,6 +807,9 @@
case 's':
suppress_non_delimited = true;
+ break;
+ case 'z':
+ delim_squeeze = true;
break;
case_GETOPT_HELP_CHAR;
- [PATCH] [cut] Treat consecutive delimiters as one in cut binary,
Joe Maimon <=