Using only awk:
> echo '$$DATABASE_AWESOME$$' | awk '{sub(/.*_/,"");sub(/\$\$$/,"");print tolower($0);}' awesome
Note that I'm on FreeBSD, so this is not GNU awk.
But this can only be done with bash:
[ ghoti@pc ~]$ foo='$$DATABASE_AWESOME$$' [ ghoti@pc ~]$ foo=${foo
Of the above substitutions, all but the last ( ${foo,,} ) will work in the standard Bourne shell. If you don't have bash, you can use tr for this step instead:
$ echo $foo AWESOME $ foo=$(echo "$foo" | tr '[:upper:]' '[:lower:]') $ echo $foo awesome $
UPDATE
In the comments, it seems that the OP really wants to separate the substring from any text in which it is included - that is, our decisions should take into account the possibility of leading or trailing spaces before or after the line that he provided in his question.
> echo 'foo $$DATABASE_KITTENS$$ bar' | sed -nE '/\$\$[^$]+\$\$/{;s/.*\$\$DATABASE_//;s/\$\$.*//;p;}' | tr '[:upper:]' '[:lower:]' kittens
And if you have pcregrep in your path (from the devel/pcre FreeBSD port), you can use it instead with lookaheads:
> echo 'foo $$DATABASE_KITTENS$$ bar' | pcregrep -o '(?!\$\$DATABASE_)[AZ]+(?=\$\$)' | tr '[:upper:]' '[:lower:]' kittens
(For Linux users reading this: this is equivalent to using grep -P .)
And in pure bash:
$ shopt -s extglob $ foo='foo $$DATABASE_KITTENS$$ bar' $ foo=${foo##*(?)\$\$DATABASE_} $ foo=${foo%%\$\$*(?)} $ foo=${foo,,} $ echo $foo kittens
Note that NONE of these three updated solutions will handle situations where multiple tags with database names exist on the same input line. This is also not indicated as a requirement in the question, but I just say that ...