Skip to main content
added 242 characters in body
Source Link
Joseph R.
  • 40.5k
  • 8
  • 113
  • 146

If all you care about is what comes to the right of = if what's on the left is -DnodeId, you can do this:

NODE=$(pargs -l $PID| awk -F '-DnodeId=' '{sub(" .*","",$2);print $2}')

This will print whatever comes to the right of the pattern -DnodeId= up to but excluding the first space. If there's more than one -DnodeId on the command line, it will work with the first one only.

To handle more than one -DnodeId per line is also possible:

NODES=($(pargs -l $PID| awk -F '-DnodeId=' '{
          for(i=2;i<=NF;i++){
              sub(" .*","",$i);
              print $i
          }
        }'
))

If all you care about is what comes to the right of = if what's on the left is -DnodeId, you can do this:

NODE=$(pargs -l $PID| awk -F '-DnodeId=' '{sub(" .*","",$2);print $2}')

This will print whatever comes to the right of the pattern -DnodeId= up to but excluding the first space. If there's more than one -DnodeId on the command line, it will work with the first one only.

If all you care about is what comes to the right of = if what's on the left is -DnodeId, you can do this:

NODE=$(pargs -l $PID| awk -F '-DnodeId=' '{sub(" .*","",$2);print $2}')

This will print whatever comes to the right of the pattern -DnodeId= up to but excluding the first space. If there's more than one -DnodeId on the command line, it will work with the first one only.

To handle more than one -DnodeId per line is also possible:

NODES=($(pargs -l $PID| awk -F '-DnodeId=' '{
          for(i=2;i<=NF;i++){
              sub(" .*","",$i);
              print $i
          }
        }'
))
deleted 4 characters in body
Source Link
Joseph R.
  • 40.5k
  • 8
  • 113
  • 146

If you all you care about is what comes to the right of = if what's on the left is -DnodeId, you can do this:

NODE=$(pargs -l $PID| awk -F '-DnodeId=' '{sub(" .*","",$2);print $2}')

This will print whatever comes to the right of the pattern -DnodeId= up to but excluding the first space. If there's more than one -DnodeId on the command line, it will work with the first one only.

If you all you care about is what comes to the right of = if what's on the left is -DnodeId, you can do this:

NODE=$(pargs -l $PID| awk -F '-DnodeId=' '{sub(" .*","",$2);print $2}')

This will print whatever comes to the right of the pattern -DnodeId= up to but excluding the first space. If there's more than one -DnodeId on the command line, it will work with the first one only.

If all you care about is what comes to the right of = if what's on the left is -DnodeId, you can do this:

NODE=$(pargs -l $PID| awk -F '-DnodeId=' '{sub(" .*","",$2);print $2}')

This will print whatever comes to the right of the pattern -DnodeId= up to but excluding the first space. If there's more than one -DnodeId on the command line, it will work with the first one only.

Source Link
Joseph R.
  • 40.5k
  • 8
  • 113
  • 146

If you all you care about is what comes to the right of = if what's on the left is -DnodeId, you can do this:

NODE=$(pargs -l $PID| awk -F '-DnodeId=' '{sub(" .*","",$2);print $2}')

This will print whatever comes to the right of the pattern -DnodeId= up to but excluding the first space. If there's more than one -DnodeId on the command line, it will work with the first one only.