GNU bug report logs -
#21865
Parenthesis subexpressions
Previous Next
Full log
Message #17 received at 21865 <at> debbugs.gnu.org (full text, mbox):
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
This bug report was last modified 9 years and 170 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.