0

I am trying to modify the output of a command , store it to a variable and pass it to another command in a single line. I tried using xargs, but didnt work well.

hre is the first command

echo "DIS NAMELIST(CLUSNL.TO.QMWC.SSL) NAMES"|runmqsc -w 10 -x QMWC |grep NAMES |grep -v DIS

output is

NAMES(CLDEV.ISCC.74                                   ,CLPRF.ISCC.74                                   ,CLSYS.ISCC.74)

Modified ouput is to remove CLDEV.ISCC.74 and store the modified output to a variable

NAMES(CLPRF.ISCC.74                                   ,CLSYS.ISCC.74)

new command to be issued

echo "ALTER NAMELIST(CLUSNL.TO.QMWC.SSL) $VARIABLE"|runmqsc -w 10 -x QMWC |grep NAMES |grep -v DIS

Here is what I could get to get the desired output, but trying to figure out how to store this to a variable and pass it to new command

`echo "DIS NAMELIST(CLUSNL.TO.QMWC.SSL) NAMES"|runmqsc -w 10 -x QMWC |grep NAMES |grep -v DIS|sed 's/CLDEV.ISCC.74`                                   ,//'
MO12
  • 369
  • 1
  • 5
  • 17
  • So, your question is [How can I assign the output of a command to a shell variable?](https://unix.stackexchange.com/questions/16024/how-can-i-assign-the-output-of-a-command-to-a-shell-variable) - or something else? – steeldriver Jun 26 '19 at 17:36

1 Answers1

0

To store the result without CLDEV.ISCC.74..., into variable VARIABLE, use:

VARIABLE=$(echo "DIS NAMELIST(CLUSNL.TO.QMWC.SSL) NAMES"|runmqsc -w 10 -x QMWC |grep NAMES |grep -v DIS | sed 's/CLDEV\.ISCC\.74[[:space:]]*,//')

Your new command should work as expected.

Freddy
  • 25,172
  • 1
  • 21
  • 60
  • I am trying to feed the variable into a command on the same line like below echo "DIS NAMELIST(CLUSNL.TO.QMWC.SSL) NAMES"|runmqsc -w 10 -x QMWC |grep NAMES |grep -v DIS | sed 's/CLDEV\.ISCC\.74[[:space:]]*,//' | echo "ALTER NMELIST((CLUSNL.TO.QMWC.SSL) NAMES"|runmqsc – MO12 Jun 26 '19 at 17:46
  • You could replace `$VARIABLE` of your new command with the content of `$(...)` (if that's what you mean), but I think the code gets unreadable and messy. – Freddy Jun 26 '19 at 17:50