On Tue, 20 Dec 2022 at 21:10, The Wanderer <wande...@fastmail.fm> wrote: > On 2022-12-20 at 02:51, Thomas Schmitt wrote:
> >>> offst=$( expr \ > >>> $( grep -a -o -b -m 1 CD001 cdimage.iso \ > >>> | sed -e 's/:/ /' \ > >>> | awk '{ print $1 }' ) - 32769 ) > > > > The Wanderer wrote: > >> Cutting down the command line led me to discover that even with '-m 1', > >> four different numbers are printed by the grep-pipeline subshell. > >> (Without '-m 1', seven are printed.) > > > > This contradicts the promises of man grep about option -m. > > It does seem to, at least at a glance - but I think I've figured out > what's going on, and it's actually consistent with the option set you > gave. [...] Hi, Slightly offtopic rambling ... I haven't looked at the 'grep' part of the above expression, but I assume that its output lines look something like: 100:CD001 If that is the case, then awk does not need any assistance from 'expr' or 'sed' (and even not from 'grep' if we were not searching a binary file). Short demo: $ echo 100:CD001 | awk 'BEGIN { FS=":" } /CD001/ { print $1 - 50 }' 50 I only write this because I just magine how poor old 'awk' feels: "don't embed me in this pipelines and subshells and unnecessary commands, I can do all that stuff myself without any help!!".