Extract regular expression group match using grep or sed

I’ve been looking for a GNU/Linux command that matches lines in a text file using a regular expression and extracts a group match for that expression (a sub-match within parenthesis).


echo 'CREATE TABLE `offercalc_fields` (' | sed -nr 's/^CREATE TABLE `(.+)\_(.*)`.*/first_word='\1', second_word='\2'/p'

cat file-permission.log | sed -nr "s/^mode of \`(.*)' changed from (....).*/chmod -c \2 \1/p"

zcat -f *.gz | sed -nr 's/^.*found (.*)\@\:*/\1/p' | sort | uniq

zcat -f exceptions.*.log.gz |grep 'exception of' | sed -nr 's/^\[([[:digit:]]+-[[:digit:]]+-[[:digit:]]+) ([[:digit:]]+).*/\1 \2/p' | uniq

zcat -f exceptions.* |grep 'exception of' | sed -nr 's/^\[([[:digit:]]+-[[:digit:]]+-[[:digit:]]+) ([[:digit:]]+).*/\1 \2/p' | uniq

zcat -f /var/log/squid/squid-access.log | grep -iv 'cache' | sed -nr 's/^.*\|.*\|.*\[(..\/...\/....):(..:..).*/\1 \2/p' | uniq

zcat -f /var/log/squid/squid-access.log | grep -iv 'cache' | sed -nr 's/^.*\[(..\/...\/....):(..:..).*/\1 \2/p' | uniq