Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save opsb/4409156 to your computer and use it in GitHub Desktop.

Select an option

Save opsb/4409156 to your computer and use it in GitHub Desktop.
Capture regex group from each line in STDIN
function regex { gawk 'match($0,/'$1'/, ary) {print ary['${2:-'0'}']}'; }
# 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