You could solve this problem quite differently. Rather than have a robot which
does typing for you, you could make simple shell function which looks like
grep, but also incorporates awk syntax, e.g:
# grok is homonymous with "grawk": grep-awk
grok [grep-opts] pattern [awk-opts] [awk-script] files...
What this will do is transform the grep options and pattern into
an awk pattern/rule combo and combine it with the awk-opts and awk-script.
Then immediately invoke the translation.
Example:
grok -v 'foo' abc.txt
-->
awk -F: '!/foo/ { print }' abc.txt
# --body introduces custom body. Default body is '@@ { print }'
# @@ is replaced with grok's translation of grep pattern.
grok -v 'foo' -F: --body 'BEGIN {x = 42} @@ { counter ++ } { print "blah" }' abc.txt
--->
awk -F: 'BEGIN {x = 42} !/foo/ { counter++ } END { print "blah" }' abc.txt
So initially, you use grok like grep, and you can add some awk logic:
same use case. If you really want to capture the translation, grok
can have a --dump option for that or whatever.
Robots that retype stuff for you are cool, but functional and syntactic
abstraction rules.
One advantage is that after hacking on the awk logic, you still have
the search pattern in grep syntax and can edit it that way.
"Oh, I wanted 'grep -B 2 pattern', not 'grep pattern'." No problem!
Just recall the grok command with all your Awk embellishments
and then and just add -B 2.
With your approach, you have to start a new 'grep -B 2' command, have it
translated to awk all over again, and then merge your previous awk work into
the resulting expansion.