coreutils
[Top][All Lists]
Advanced

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

Re: RFE: head,tail: -z, --zero-terminated


From: Assaf Gordon
Subject: Re: RFE: head,tail: -z, --zero-terminated
Date: Fri, 8 Jan 2016 14:20:25 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0

Hello Pádraig and all,

Regarding the "wc", I think the following is missing:
===
diff --git a/src/wc.c b/src/wc.c
index ea2c20f..0e9a849 100644
--- a/src/wc.c
+++ b/src/wc.c
@@ -651,7 +651,7 @@ main (int argc, char **argv)
   print_linelength = false;
   total_lines = total_words = total_chars = total_bytes = max_line_length = 0;
- while ((optc = getopt_long (argc, argv, "clLmw", longopts, NULL)) != -1)
+  while ((optc = getopt_long (argc, argv, "clLmwz", longopts, NULL)) != -1)
     switch (optc)
       {
       case 'c':
===


Also,
If I understand what the patch does, it only changes the delimiter of the 
output line,
but still treats NL as the input delimiters ?

e.g. the following gives 2 instead of 1:

    $ printf "a\nb\nc\x00" | ./src/wc -z -l
    2

I can understand if the goal is to be strict POSIX-like (and always count NLs, 
not logical lines),
but this can lead to counter-intuitive results when combined with other 
programs.

Since this returns 10:

    $ cat FOO | head -n10 | wc -l

I would naively expect this to return 10 as well:

    $ cat null-terminated-FOO | head -z -n10 | wc -z -l

And similarly:

    $ cat FOO | tr '\n' '\0' | head -z -n10 | wc -z -l

but currently it will return 0 (or as many embedded NLs that are in the input, 
but not 10).

What do you think?


regards,
 - assaf




reply via email to

[Prev in Thread] Current Thread [Next in Thread]