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`                                   ,//'
1

1 Answer 1

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.

2
  • 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, 2019 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, 2019 at 17:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .