Extract string from output.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract string from output.
# 1  
Old 02-21-2013
Wrench Extract string from output.

I need to extract the the values of "Java"and "-Dplatform.home" from the output of the below ps command.

Code:
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:

Quote:
java_home=/app1/jdk150_07 [Which should be extracted from "/app1/jdk150_07/bin/IA64N/java"]

wls_home=/app1/bea/weblogic92
I am using HP-UX. Kindly help.

Last edited by mohtashims; 02-21-2013 at 08:40 AM..
# 2  
Old 02-21-2013
Try sth like this..

Code:
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

This User Gave Thanks to pamu For This Post:
# 3  
Old 02-21-2013
Quote:
Originally Posted by pamu
Try sth like this..

Code:
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

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.
# 4  
Old 02-21-2013
so use Dplatform instead of weblogic...

Code:
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 User Gave Thanks to pamu For This Post:
# 5  
Old 02-21-2013
Quote:
Originally Posted by pamu
so use Dplatform instead of weblogic...

Code:
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 .
# 6  
Old 02-21-2013
You can use pipe for this...

just like this..

Code:
ps | awk {.....}

This User Gave Thanks to pamu For This Post:
# 7  
Old 02-26-2013
Question

Quote:
Originally Posted by pamu
so use Dplatform instead of weblogic...

Code:
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to extract every repeated string between two specific string?

Hello guys, I have problem with hpux shell script. I have one big text file that contains like SOH bla bla bla bla bla bla ETX SOH bla bla bla ETX SOH bla bla bla ETX What I need to do is save first SOH*BLA into file1.txt, save second SOH*BLA into file2.txt and so on.... (17 Replies)
Discussion started by: sembii
17 Replies

2. Shell Programming and Scripting

To Search for a string and to extract the string from the text

Hi Team I have an huge xml where i need to search for a ceratin numbers. For example 2014-05-06 15:15:41,498 INFO WebContainer : 10 CommonServicesLogs - CleansingTriggerService.invokeCleansingService Entered PUBSUB NOTIFY MESSAGE () - <?xml version="1.0" encoding="UTF-8"... (5 Replies)
Discussion started by: Kannannair
5 Replies

3. Shell Programming and Scripting

Search String and extract few lines under the searched string

Need Assistance in shell programming... I have a huge file which has multiple stations and i wanted to search particular station and extract few lines from it and the rest is not needed Bold letters are the stations . The whole file has multiple stations . Below example i wanted to search... (4 Replies)
Discussion started by: ajayram_arya
4 Replies

4. Shell Programming and Scripting

Extract a string from another string in UNIX

I have a string string="Please have a nice day and sleep well Replace_12123_31233_32134_12342 Good day" How do i replace "Replace_12123_31233_32134_1234" in the above string.?? Please help. Regards, Qwerty (3 Replies)
Discussion started by: qwertyu
3 Replies

5. Shell Programming and Scripting

Extract a string between 2 ref string from a file

Hi, May i ask if someone share some command for extracting a string between 2 ref string in a txt file My objective: i had a file with multiple lines and wants only to extract the string "watch?v=IbkAXOmEHpY" or "watch?v=<11 random character>", when i used "grep 'watch?=*' i got a results per... (4 Replies)
Discussion started by: jao_madn
4 Replies

6. Shell Programming and Scripting

to extract string from main string and string comparison

continuing from my previous post, whose link is given below as a reference https://www.unix.com/shell-programming-scripting/171076-shell-scripting.html#post302573569 consider there is create table commands in a file for eg: CREATE TABLE `Blahblahblah` ( `id` int(11) NOT NULL... (2 Replies)
Discussion started by: vivek d r
2 Replies

7. Shell Programming and Scripting

extract a string within a string using a pattern

hi all, i have a file name using the following pattern: PREFIX: AR SOURCE: LEGACY DATETIME: YYYYMMDD_HH24MISS SUFFIX: .txt sample filename: AR_LEGACY_20101104_105500.txt i want to extract the source which is LEGACY in this case. how do i do this using shell? thanks. (4 Replies)
Discussion started by: adshocker
4 Replies

8. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

9. Shell Programming and Scripting

extract a string from main string

i need a shell program,to extract a string from a main string. main string is "madhu" sub string is "mad"..means any word from the main string please di this (1 Reply)
Discussion started by: madhu.it
1 Replies

10. Shell Programming and Scripting

extract a sub string from a main string

i need a shell program to extract a substring from a main string.. for eg:- main string is madhu.. sub string is mad o/p:- be mad. try to solve this one (5 Replies)
Discussion started by: madhu.it
5 Replies
Login or Register to Ask a Question