1

Can you please help me with a sed command to retrieve '9034' value from these JVM arguments.

-OtherJVM1=value1 -OtherJVM2=value2 -Dserver.port=9034 -Dajp.port=8534

Here is what I have tried:

sed -n -e 's/^.*\(Dserver.port=\)//p'

The above sed command is giving:

9034 -Dajp.port=8534 

But I only want '9034', within 1 command.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
DevOpsNewB
  • 185
  • 2
  • 14

2 Answers2

1

Try this simple sed command

sed 's/.*Dserver.port=\([^ ]\+\).*/\1/'  <<< "-OtherJVM1=value1 -OtherJVM2=value2 -Dserver.port=9034 -Dajp.port=8534"
Kalanidhi
  • 4,902
  • 27
  • 42
0

I don't use SED, but if instead of a "." (dot) in your regex you use a \d, it should match any number of digits after Dserver.port=, without capturing the rest of the string.

Asunez
  • 2,327
  • 1
  • 23
  • 46