I need to extract the the values of "Java"and "-Dplatform.home" from the output of the below ps command.
ps -xef | grep java
wlsuser 15160 15144 0 Feb 20 ? 17:27 /app1/jdk150_07/bin/IA64N/java -server -Xms1536m -Dplatform.home=/app1/bea/weblogic92 -Dwli.home=/app1/bea/weblogic92/integration
Desired output:
I am using HP-UX. Kindly help.
pamu
February 21, 2013, 6:50am
2
Try sth like this..
awk 'BEGIN{X[1]="java_home=";X[2]="wls_home="}
{for(i=1;i<=NF;i++){if($i ~ /weblogic92$|java$/){split($i,P,"=");s=P[2]?P[2]:$i;print X[++a]""s}}}' file
1 Like
I guess you are using "weblogic92" as the parameter to trim the wls_home but I need to trim using "-Dplatform.home" because in other output weblogic92 may change to weblogic103 or something else while "-Dplatform.home" will always remain the same.
So I guess it will not help me.
pamu
February 21, 2013, 8:05am
4
so use Dplatform instead of weblogic...
awk 'BEGIN{X[1]="java_home=";X[2]="wls_home="}
{for(i=1;i<=NF;i++){if($i ~ /-Dplatform\.home|java$/){split($i,P,"=");s=P[2]?P[2]:$i;print X[++a]""s}}}' file
1 Like
pamu:
so use Dplatform instead of weblogic...
awk 'BEGIN{X[1]="java_home=";X[2]="wls_home="}
{for(i=1;i<=NF;i++){if($i ~ /-Dplatform\.home|java$/){split($i,P,"=");s=P[2]?P[2]:$i;print X[++a]""s}}}' file
This is the output of the ps command as in the OP. I do not have any file to input to the awk. can you help with that change. I will be thankful .
pamu
February 21, 2013, 8:39am
6
You can use pipe for this...
just like this..
ps | awk {.....}
1 Like
pamu:
so use Dplatform instead of weblogic...
awk 'BEGIN{X[1]="java_home=";X[2]="wls_home="}
{for(i=1;i<=NF;i++){if($i ~ /-Dplatform\.home|java$/){split($i,P,"=");s=P[2]?P[2]:$i;print X[++a]""s}}}' file
Java_home and wls_home is populating correctly, however can you help me store them in bash variables? I am not good at awk.
Shahul
February 26, 2013, 9:11am
8
Hi Mohtasims
What pamu given is working fine, however u asked for bash to store in variable....
weblogichome=`ps -ef |cut -d"=" -f2-3|awk '{print $1}'`
javahome=`ps -ef |cut -d"/" -f2-3|sed 's/^/\//g'`
I have used very basic commands to make ur output requested....
Thanks
Sha
shahul:
Hi Mohtasims
What pamu given is working fine, however u asked for bash to store in variable....
weblogichome=`ps -ef |cut -d"=" -f2-3|awk '{print $1}'`
javahome=`ps -ef |cut -d"/" -f2-3|sed 's/^/\//g'`
I have used very basic commands to make ur output requested....
Thanks
Sha
I think you are not considering ""-Dplatform.home" and "java" to grep the weblogichome & jdkhome :(. I want them considered.