Quantcast
Viewing latest article 2
Browse Latest Browse All 11

Answer by opsb for Capturing Groups From a Grep RegEx

This is a solution that uses gawk. It's something I find I need to use often so I created a function for it

function regex1 { gawk 'match($0,/'$1'/, ary) {print ary['${2:-'1'}']}'; }

to use just do

$ echo 'hello world' | regex1 'hello\s(.*)'
world

Viewing latest article 2
Browse Latest Browse All 11

Trending Articles