Timeline for How can I output only captured groups with sed?
Current License: CC BY-SA 2.5
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
May 15, 2017 at 19:36 | comment | added | abalter |
Also, you can't do echo "a 10 b 12" | grep -Eo "a ([0-9]+)" and get just the "10". But this works: echo "a 10 b 12" | grep -Eo "a ([0-9]+)" | sed 's/a //'
|
|
Oct 3, 2012 at 17:56 | comment | added | idbrii |
@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).
|
|
Mar 14, 2011 at 8:30 | comment | added | doc_id | Hello Michael. Did you managed to extract nth captured group by grep ? | |
May 6, 2010 at 12:11 | comment | added | Pablo | @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. | |
May 6, 2010 at 11:36 | comment | added | Bert F |
@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
|
|
May 6, 2010 at 1:24 | comment | added | Pablo | @ghostdog74: Absolutely agree with you. How can I get greo to output only captured groups? | |
May 6, 2010 at 1:11 | history | answered | ghostdog74 | CC BY-SA 2.5 |