The requirement is to compare A.txt output with the above B.txt output and get the matched strings. Pass those strings as a argument to another command.
If B.txt contains the command you specified above, there will be no output at all (unless there are diagnostic messages produced by dspmq ). Any output printed to standard output by that pipeline is stored in the variable QMGR , but since that variable is never referenced after it is set, that script does not produce any output on the standard output file descriptor.
To get what you seem to want, you could try something like:
another_ccommand "$(dspmq | awk -F '[()]' 'FNR == NR {a[$2]; next} $1 in a' A.txt FS='[ \t]' -)"
Why would you remove A.txt and B.txt ? I didn't see anything in the OP's posts indicating that either file would no longer be needed after one run of this script.
Why invoke cut twice and fgrep once when a single invocation of awk easily replaces all three.
Of course we are both assuming that the output from dspmq contains a parenthesized string before any spaces or tabs. Since we don't know what that output actually contains,we're both flying blind.