capture a word from the output
Hi,
I am trying to catch a value of a variable from a java process from command-line on linux. I search for a process using 'ps -ef' command and get a output like ======================================================= 500 7581 5520 0 00:36 ? 00:00:20 /usr/java/jdk1.6.0_34/jre/bin/java -Xrs -cp ":/foo/barr//bpmengine/bpmengine.jar:/foo/barr//dbconnection/dbconnection.jar:/foo/barr//coboc/coboc.jar:/foo/barr//wsappserver/wsappserver.jar:/foo/barr//scheduler/scheduler.jar:/foo/barr//datamapper/datatransform.jar:/foo/barr//datamapper/binarytransform.jar:/foo/barr//ruleengine/ruleengine.jar:/foo/barr//expressioneval/expressioneval.jar:/foo/barr//audit/auditartifactapi.jar:/foo/barr//audit/auditartifact.jar:/foo/barr//statemachine/statemachine.jar:/opt/abcd/defaultInst/ext/xbean.jar:/foo/barr//bpmengine/dom4j.jar:/foo/barr//bpmengine/geronimo-stax.jar:/foo/barr//bpmengine/poi-ooxml.jar:/foo/barr//bpmengine/poi-ooxml-schemas.jar:/foo/barr//search/poi-3.6-20091214.jar:/foo/barr//bpmengine/bpmengine.jar:/foo/barr//dbconnection/dbconnection.jar:/foo/barr//dbconnectors/dbconnectors.jar:/foo/barr//coboc/coboc.jar:/opt/abcd/defaultInst/ext/xbean.jar:/foo/barr//bpmengine/dom4j.jar:/foo/barr//bpmengine/geronimo-stax.jar:/foo/barr//bpmengine/poi-ooxml.jar:/foo/barr//bpmengine/poi-ooxml-schemas.jar:/foo/barr//search/poi-3.6-20091214.jar:/opt/abcd/defaultInst/abcdcp.jar:/opt/abcd/defaultInst/abcdcp.jar:/usr/lib/mysql-connector-java-5.1.12-bin.jar:/usr/lib/mysql-connector-java-5.1.12-bin.jar::/usr/lib/mysql-connector-java-5.1.21-bin.jar::" -DProcessName=App1 -XX:PermSize=5m -Xmx512M -Dabcd_INSTALL_DIR=/opt/abcd/defaultInst com.eibus.soap.Processor -binary -name 34:115:121:115:116:101:109:35:98:117:115:105:110:101:115:115:95:112:114:111:99:101:115:115:95:109:97 :110:97:103:101:109:101:110:116:35:98:117:115:105:110:101:115:115:95:112:114:111:99:101:115:115:95:1 09:97:110:97:103:101:109:101:110:116:34: ====================================================== In the above output, there is a string called "-DProcessName=App1". the value of the variable "DProcessName" keeps changing. I want to capture the value of the processname only. please notice that the ouput of 'ps -ef' command always is in a single line. Please help in finding a solution. |
grep -o would probably help in this instance.
|
Hi,
grep -o option is not helping in this case, for example, If I give, grep -o ProcessName, only ProcessName will be the output, not its value. |
grep -o ProcessName.*" "; maybe awk/sed/cut would fit better. you have many options.
|
In your example, the value of '-DProcessName' is 'App1'.
If you are sure that there will be no space between your values and output of 'ps -ef' is printed in one line like you have put in your post then following command can work for you. Code:
ps -ef | sed -e 's/.*-DProcessName=//g' -e 's/ .*//g' Generally 'ps -ef' command's out put looks like this. It is appeared in columns. Code:
UID PID PPID C STIME TTY TIME CMD |
More concisely:
Code:
ps -ef | sed -r 's/.*-DProcessName=([^ ]+).*/\1/' |
Thank you
Hi All,
Thank you all for the help. I am very bad at working with regular expressions. I will start working on it. |
All times are GMT -5. The time now is 05:30 PM. |