Is it possible to extract these values from the output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Is it possible to extract these values from the output
# 1  
Old 02-27-2013
Is it possible to extract these values from the output

Hi,

I would like to search based of "java" and "-Dplatform.home=" and store these two values in bash variables.

Code:
 
ps -xef | grep <pid>
     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 ouput:
Code:
 
java_home=/app1/jdk150_07/bin/IA64N/java 
weblogic_home=/app1/bea/weblogic92

# 2  
Old 02-27-2013
I guess this has been answered in this thread

https://www.unix.com/shell-programmin...ng-output.html
# 3  
Old 02-27-2013
Wrench

Quote:
Originally Posted by Vikram_Tanwar12
I guess this has been answered in this thread

https://www.unix.com/shell-programmin...ng-output.html
It has not been answered and that is the very reason I opened the new thread. I want them to be stored in variables which is the addressed in the previous thread. Kindly help.
# 4  
Old 02-27-2013
Why don't you help yourself? That would be very educational! All pieces of the puzzle (parts of the solution) are given in that previous thread, you just need to get your ducks in a row.
# 5  
Old 02-27-2013
Quote:
Originally Posted by RudiC
Why don't you help yourself? That would be very educational! All pieces of the puzzle (parts of the solution) are given in that previous thread, you just need to get your ducks in a row.
If your intention is to question my naive skills on unix and / or the efforts put in then below is what i unsuccessfully tried.

Code:
eblogic_jdk_home=$($pscmd $weblogic_pid | awk 'BEGIN{X[1]="java_home="}{for(i=1;i<=NF;i++){if($i ~ /java$/){split($i,P,"=");s=P[2]?P[2]:$i;print X[++a]""s}}}')

But it does not give me the desired output. Can you help find me a solution ?
# 6  
Old 02-27-2013
Well, honouring your little effort, I'll try my best. That is not so easy - your wishes and specifications change form post to post and from thread to thread. Pulling some info together from the various sources, and given the fact that I can't duplicate your ps output so I use a file input, I've come up with
Code:
TMP=$(awk       '/java/         {printf "/%s/%s", $2, $3}
                 /platform/     {printf "|%s\n", $NF}
                ' FS="/" RS=" +" file )
weblogic_home=${TMP#*|}
java_home=${TMP%|*}
echo $java_home $weblogic_home
/app1/jdk150_07 weblogic92

It is well possible that your awk implementation does not accept e.g. the RS pattern; then we need to play on...
# 7  
Old 02-27-2013
Code:
var=`ps -xef | grep <pid>`
echo $var|tr " " "\n" | grep jdk150_07|sed "s/^/java_home=/g"
echo $var|tr " " "\n"|grep platform|sed 's/-Dplatform.home=/weblogic_home=/g'

Check out if you get the required o/p

Last edited by Franklin52; 02-27-2013 at 08:36 AM.. Reason: Please use code tags for data and code samples
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract values only for certain tags

Hi Please I need help on extracting values, of certain tagsMSISDN:, and IMSI: in the following text file entryDS: 1 nodeId: 11 MSISDN: 258827475309 IMSI: 643012111658984 NAM: 0 CDC: 41 IMEISV:: U3URIGF2hoc= AUTHINFO: 0 TSMO:... (16 Replies)
Discussion started by: fretagi
16 Replies

2. Shell Programming and Scripting

Extract rows with different values at 2 columns

Hallo, I would need to extract only rows which has different value in the second and third column. Thank you very much for any advices Input: A 0 0 B 0 1 C 1 1 D 1 3 Output B 0 1 D 1 3 (4 Replies)
Discussion started by: kamcamonty
4 Replies

3. Shell Programming and Scripting

Extract values

hi I have a line as given below. I need to match "COLUMN_NAME" and get the every third value ie words in between quotes completely (' ') Sample Input - COLUMN_NAME Like '%value%' Or COLUMN_NAME Like '%value%' Or COLUMN_NAME Like '%value value%' Or COLUMN_NAME Like '%value%' OR... (5 Replies)
Discussion started by: Prashanth B
5 Replies

4. Shell Programming and Scripting

Extract multiple values from a tnsping output

Hi all, Can anyone help with the following request? I need to extract HOST value, SERVICE_NAME and msec value from a tnsping output and append to a file. The tnsping output is typically as follows: Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS =... (4 Replies)
Discussion started by: jonnyd
4 Replies

5. Shell Programming and Scripting

Extract values from Perl variable

Hi Guys, I am stuck in a problem. I have a variable in Perl script which has value for example X=a-b-c; Now, I want to extract a b c separately into different 3 variables. I know this can be done in shell using awk but Perl behaves a bit different. Can anybody help me on this please?... (3 Replies)
Discussion started by: prashant2507198
3 Replies

6. Shell Programming and Scripting

Using dynamic arrays to extract the values

Hi all, We have requirement to generate load timing based on subject areas HOUSEHOLD, BANKING and TRADING. These values are stored in an array SUB_ARR SUB_ARR=("HOUSEHOLD" "BANKING" "TRADING") Based on indicator files produced while processing data for each type, we need to get the stats (using... (2 Replies)
Discussion started by: sanjaydubey2006
2 Replies

7. Shell Programming and Scripting

extract key values

I am parsing a log with key values spread all over in the following fashion: TEST 1 SCHEME 12 SET EMPTY VARLEN SET TEST 1201 PARAM1 EMTY PARAM2 SET SCHEME 12 REFRESH TEST 8 I need to extract test number, my result should be 1 1201 8 I use awk for processing this log and use... (4 Replies)
Discussion started by: migurus
4 Replies

8. Shell Programming and Scripting

Extract Values from CSV

Hi, I need to extract values from a CSV file based on some conditions as explained below: File format details: 1. each set starts with AAA only 2. number of columns is fixed 3. number of rows per set may vary (as they are having different CCC rows) Now, i need to extract 3rd column of... (3 Replies)
Discussion started by: prvnrk
3 Replies

9. Shell Programming and Scripting

how to extract values b/w two delimiters

Hi, Please help me to extrat values b/w two delimiters. $ echo $abc i want to extract the value 12345 b/w %. (5 Replies)
Discussion started by: tsaravanan
5 Replies

10. Shell Programming and Scripting

Extract values from log file

I would like to write a shell script that will parse through a file similar to the sample below. The data in the file is redirected from rsync into a log file. I would like to call a shell script to parse through and pick out the number beside the percent sign inside the parentheses in the last... (5 Replies)
Discussion started by: wdympcf
5 Replies
Login or Register to Ask a Question