Strip output from ps command in unix

I need to return only partial output from ps -ef command either using awk/sed/.. Below is the command that i am running. I need the value returned only for weblogic.home ( /u01/app/xxxx/product/fmw/wlserver/server ) from the entire output. The weblogic.home value might be in the middle of the output as well .. so i need to cut with keyword weblogic.home to retrieve the value.

$ps -ef | grep weblogic.home | grep -v grep | head -1

test 26263 26206  0 Aug02 ?        07:26:15 /u01/app/xxxx/jdk1.8.0_251/bin/java -server -Xms256m -Xmx512m -cp xxxxxxx/server/lib/weblogic-launcher.jar -Dlaunch.use.env.classpath=true -Dweblogic.Name=xxxxxxx -Dweblogic.ProductionModeEnabled=true -Dweblogic.nodemanager.ServiceEnabled=true -Dweblogic.nmservice.RotationEnabled=true -Xms4096M -Xmx4096M -XX:+UseG1GC -XX:ParallelGCThreads=8 -XX:ConcGCThreads=2 -XX:MaxGCPauseMillis=500 -XX:+ScavengeBeforeFullGC -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:GCLogs/xxxxxxx_gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=10M -XX:+HeapDumpOnOutOfMemoryError -Doracle.jdbc.fanEnabled=false -Djava.system.class.loader=com.oracle.classloader.weblogic.LaunchClassLoader -javaagent:/u01/app/oracle/product/fmw/wlserver/server/lib/debugpatch-agent.jar -da -Dwls.home=/u01/app/xxxx/product/fmw/wlserver/server -Dweblogic.home=/u01/app/xxxx/product/fmw/wlserver/server -Dweblogic.management.server=http://xxxxxxxx:xxxxx weblogic.Server

So the actual output that i need is

$ps -ef | grep weblogic.home | grep -v grep | head -1

/u01/app/oracle/product/fmw/wlserver/server

Upvotes: 1

Views: 250

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133458

Since OP didn't show actual Input and only showed output of his attempt so I am taking his command's output as an Input for this command, though I strongly recommend that we could do this in a single awk itself.

your_command | awk 'match($0,/-Dweblogic.home=[^ ]*/){print substr($0,RSTART,RLENGTH)}'

Explanation: Simply using match function of awk and matching from -Dweblogic.home= to till first occurrence of space comes and printing the matched regex part.

Upvotes: 2

Related Questions