Skip to main content
The 2024 Developer Survey results are live! See the results

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 5
    @ghostdog74: Absolutely agree with you. How can I get greo to output only captured groups?
    – Pablo
    Commented May 6, 2010 at 1:24
  • 2
    @Michael - that's why the o option is there - unixhelp.ed.ac.uk/CGI/man-cgi?grep : -o, --only-matching Show only the part of a matching line that matches PATTERN
    – Bert F
    Commented May 6, 2010 at 11:36
  • 22
    @Bert F: I understand the matching part, but it's not capturing group. What I want is to have like this ([0-9]+).+([abc]{2,3}) so there are 2 capturing groups. I want to output ONLY capturing groups by backreferences or somehow else.
    – Pablo
    Commented May 6, 2010 at 12:11
  • Hello Michael. Did you managed to extract nth captured group by grep ?
    – doc_id
    Commented Mar 14, 2011 at 8:30
  • 2
    @Pablo: grep's only outputting what matches. To give it multiple groups, use multiple expressions: grep -Eow -e "[0-9]+" -e "[abc]{2,3}" I don't know how you could require those two expressions to be on one line aside from piping from a previous grep (which could still not work if either pattern matches more than once on a line).
    – idbrii
    Commented Oct 3, 2012 at 17:56