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: Pádraig Brady
Subject: Re: RFE: head,tail: -z, --zero-terminated
Date: Fri, 8 Jan 2016 16:56:44 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

On 28/09/15 15:17, Stephane Chazelas wrote:
> 2015-09-26 15:43:40 +0100, Richard Russon:
>> I'd like to add an option to both head and tail,
>> to allow them to work with NUL-terminated lines of text
>>     -z, --zero-terminated
>>
>> Thus allowing:
>>
>>     find dir -type f -print0 | head -z -n 10 | xargs -0 command
> [...]
> 
> See also
> 
> sed -z 10q
> 
> as an alternative to
> 
> head -zn 10
> 
> While we're at it, why not add it to every text utility (cut,
> paste, seq, yes, tac...) for those that don't have it already?

Yes we've been adding -z support piecemeal over time,
so I propose we add this as per the attached patch set to:
wc, comm, cut, head, tail, tac, paste

When looking at coreutils which might benefit from -z
I split them into four categories:

1. One output item per input argument.
NUL terminated input is catered for by xargs.

NUL terminated output is handled with -z,--zero
already for these utils:

  basename
  dirname
  du
  readlink
  realpath
  stat (handled with --printf='...\0')
  md5sum (\n is escaped)
  sha*sum (ditto)
  ls (ditto, also \0 supported by find)

Possible additions to this class:

  cksum (obsolescent)
  sum (ditto)
  wc


2. Multiple output records per input file/stdin
NUL terminated I/O is handled with -z,--zero-terminated
already for these utils:

  join
  shuf
  sort
  uniq

Possible additions to this class:

  comm
  cut
  head (especially since supports multiple files and seeking within them)
  tail (ditto)
  tac (ditto. extend -s to support '')
  paste

  nl (N/A as primarily text rather than record oriented)
  numfmt (ditto)
  expand (ditto)
  unexpand (ditto)

  fmt (N/A as word oriented rather than record oriented)
  fold (ditto)
  tsort (ditto)


3. Misc record processing

  id (handled already with -z)
  split (handled already with -t,--separator='\0')
  csplit (pattern based so only supports text)
  seq (might support -s '\0' but can't see need)
  yes (easy to handle this edge case with tr)

Attachment: coreutils--zero.patch
Description: Text Data


reply via email to

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