On Tue, Sep 25, 2018 at 06:06:06PM -0700, Taylor Blau wrote: > > > +extract_haves () { > > > + depacketize - | grep '\.have' | sed -e 's/\\0.*$//g' > > > +} > > > > Don't pipe grep into sed, especially when both the pattern to filter > > and the operation to perform are simple. > > > > I am not sure what you are trying to achive with 'g' in > > s/pattern$//g; The anchor at the rightmost end of the pattern makes > > sure that the pattern matches only once per line at the end anyway, > > so "do this howmanyever times as we have match on each line" would > > not make any difference, no? > > I admit to not fully understanding when the trailing `/g` is and is not > useful. Anyway, I took Peff's suggestion below to convert this 'grep | > sed' pipeline into a Perl invocation, which I think ended up much > cleaner. It makes the replacement global in the line. Without we substitute only the first match. So try: echo foo | sed s/o/X/ versus: echo foo | sed s/o/X/g -Peff