Re: [coreutils] [PATCH] head: optionally indicate underrun of set limit

2011-05-16 Thread Pádraig Brady
On 24/11/10 16:34, Pádraig Brady wrote:
 On 23/11/10 16:34, Pádraig Brady wrote:
 On 23/11/10 16:24, Stefan Tomanek wrote:
 Dies schrieb Stefan Tomanek (stefan.toma...@wertarbyte.de):

 It is often convinient to detect whether head has in fact printed the
 requested number of lines or if EOF was reached before reaching that
 point. This patch adds the option --indicate-underrun, which makes
 head exit with a status of 4 instead of 0 if no more data could be
 read from its input.

 Any thoughts about this change? It's a rather small patch, but would
 be quite useful (at least for me).

Note the above use case is now supported with `split --filter`
http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commit;h=a09d9e5b
(Note currently the number of chunks is limited by --suffix-length).

 The following addresses both issues and
 also uses existing coreutils functionality:
 
 process_part() { echo processing $(wc -c) bytes; }
 while true; do
   c=$(od -tx1 -An -N1)
   test $c || break
   c=$(echo $c) #strip leading ' '
   { printf \x$c; head -c9; } | process_part
 done

BTW I previously created a script with the above,
since it seems so useful. So you can use this for older systems:
https://github.com/pixelb/scripts/commits/master/scripts/split_to

cheers,
Pádraig.



Re: [coreutils] [PATCH] head: optionally indicate underrun of set limit

2010-11-24 Thread Pádraig Brady
On 23/11/10 16:34, Pádraig Brady wrote:
 On 23/11/10 16:24, Stefan Tomanek wrote:
 Dies schrieb Stefan Tomanek (stefan.toma...@wertarbyte.de):

 It is often convinient to detect whether head has in fact printed the
 requested number of lines or if EOF was reached before reaching that
 point. This patch adds the option --indicate-underrun, which makes
 head exit with a status of 4 instead of 0 if no more data could be
 read from its input.

 Any thoughts about this change? It's a rather small patch, but would
 be quite useful (at least for me).


 
 This does seem useful on the face of it.
 I need to do a little further investigation
 to see if there are existing ways to achieve the same.

I was wondering about the logic in your example BTW.
If there is no input then you'll process an empty chunk
or if the input is an exact multiple of the chunk size
you'll process an empty chunk at the end.

The following addresses both issues and
also uses existing coreutils functionality:

process_part() { echo processing $(wc -c) bytes; }
while true; do
  c=$(od -tx1 -An -N1)
  test $c || break
  c=$(echo $c) #strip leading ' '
  { printf \x$c; head -c9; } | process_part
done

cheers,
Pádraig.

p.s. \x is not a printf standard so the
script probably needs tweaking for dash

p.p.s. I noticed the related ifne util from moreutils