From 6948c2ab16a2b371d94fe81fba99e614627dba51 Mon Sep 17 00:00:00 2001 From: rofl0r Date: Thu, 16 Dec 2021 19:40:47 +0000 Subject: [PATCH] add new -count option this makes it possible to use jobflow to cut a subset of line numbers like a combination of `head` and `tail` utilities. e.g. seq 100 | jobflow -skip=10 -count=10 will print the lines from 11-20 --- jobflow.c | 14 ++++++++++++-- test.sh | 6 ++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/jobflow.c b/jobflow.c index f27da05..b58acef 100644 --- a/jobflow.c +++ b/jobflow.c @@ -146,6 +146,7 @@ typedef struct { unsigned long numthreads; unsigned long threads_running; unsigned long skip; + unsigned long count; unsigned long delayedspinup_interval; /* use a random delay until the queue gets filled for the first time. the top value in ms can be supplied via a command line switch. this option makes only sense if the interval is somewhat smaller than the @@ -371,13 +372,15 @@ static int syntax(void) { "until EOF is received. we call this 'pipe mode'.\n" "\n" "available options:\n\n" - "-skip N -threads N -resume -statefile=/tmp/state -delayedflush\n" + "-skip N -count N -threads N -resume -statefile=/tmp/state -delayedflush\n" "-delayedspinup N -buffered -joinoutput -limits mem=16M,cpu=10\n" "-eof=XXX\n" "-exec ./mycommand {}\n" "\n" "-skip N\n" " N=number of entries to skip\n" + "-count N\n" + " N=only process count lines (after skipping)\n" "-threads N (alternative: -j N)\n" " N=number of parallel processes to spawn\n" "-resume\n" @@ -453,6 +456,7 @@ static int parse_args(unsigned argc, char** argv) { {"statefile", 0, 's', .dest.s = &prog_state.statefile }, {"eof", 0, 's', .dest.s = &prog_state.eof_marker }, {"skip", 0, 'i', .dest.i = &prog_state.skip }, + {"count", 0, 'i', .dest.i = &prog_state.count }, {"resume", 0, 'b', .dest.b = &resume }, {"delayedflush", 0, 'b', .dest.b = &prog_state.delayedflush }, {"delayedspinup", 0, 'i', .dest.i = &prog_state.delayedspinup_interval }, @@ -463,6 +467,7 @@ static int parse_args(unsigned argc, char** argv) { }; prog_state.numthreads = 1; + prog_state.count = -1UL; for(i=1; i