[regex] How to print matched regex pattern using awk?

If Perl is an option, you can try this:

perl -lne 'print $1 if /(regex)/' file

To implement case-insensitive matching, add the i modifier

perl -lne 'print $1 if /(regex)/i' file

To print everything AFTER the match:

perl -lne 'if ($found){print} else{if (/regex(.*)/){print $1; $found++}}' textfile

To print the match and everything after the match:

perl -lne 'if ($found){print} else{if (/(regex.*)/){print $1; $found++}}' textfile