[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#21865: Parenthesis subexpressions
From: |
Stephane Chazelas |
Subject: |
bug#21865: Parenthesis subexpressions |
Date: |
Mon, 9 Nov 2015 17:16:19 +0000 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
2015-11-09 17:00:36 +0100, Valerio Bozzolan:
> Thanks for agreeing with the evolution of the meaning of "-o".
>
> Just to make you a laugh: I was reproducing egrep with $BASH_REMATCH:
> https://gist.github.com/valerio-bozzolan/6787675e931dce1ba7e9
>
> Definitely not beautiful... but really effective for me.
You may want to read:
https://unix.stackexchange.com/questions/169716/why-is-using-a-shell-loop-to-process-text-considered-bad-practice
https://unix.stackexchange.com/questions/209123/understand-ifs-read-r-line
https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo
Here, if there wasn't a pcregrep already, I'd rather do it in
perl or GNU sed than bash.
Like:
perl -lne 'print for /a([a-z])c/g'
Also note that:
echo abac | pcregrep -o1 'a(.)'
b
c
> So something like "egrep -o $n regex" also can save the world from code
> similar to mine.
GNU grep can't add it like that as that would break backward
compatibility.
grep -o 1 regex file
is currently meant to print the occurrences of "1" in the
"regex" and "file" files.
Even adding it as:
grep -o1 regex file
would probably not be a good idea as that would mean some
ad-hoc parsing of the options (in "grep -o1 regexp", "1" would
be an argument to "-o" while in "grep -oi regexp", "i" currently
is a separate "-i" option).
So reasonably, it should probably be a separate option like -O 1.
--
Stephane