Last active
December 10, 2015 08:38
-
-
Save opsb/4409156 to your computer and use it in GitHub Desktop.
Capture regex group from each line in STDIN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function regex { gawk 'match($0,/'$1'/, ary) {print ary['${2:-'0'}']}'; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Print regex match for each line in STDIN | |
| $ cat filename | regex '.*' | |
| # Print first regex group for each line in STDIN | |
| # cat filename | regex '(.*)' 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment