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
# 8  
Old 02-28-2013
Hammer & Screwdriver

Quote:
Originally Posted by nikhil jain
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
I don't need "java_home=" or "weblogic_home=" in the output.

All i need is the output value be assigned to bash variable. Please read OP for details.

Last edited by mohtashims; 02-28-2013 at 09:51 AM..
# 9  
Old 02-28-2013
Here is another approach:
Code:
#!/bin/bash

o=$( ps -xef | grep <pid> )

for t in $o
do
        [[ $t =~ java ]] && java_home="$t"
        [[ $t =~ -Dplatform.home ]] && weblogic_home="${t#-Dplatform.home=}"

done

This User Gave Thanks to Yoda For This Post:
# 10  
Old 02-28-2013
Wrench

Quote:
Originally Posted by bipinajith
Here is another approach:
Code:
#!/bin/bash
 
o=$( ps -xef | grep <pid> )
 
for t in $o
do
        [[ $t =~ java ]] && java_home="$t"
        [[ $t =~ -Dplatform.home ]] && weblogic_home="${t#-Dplatform.home=}"
 
done


Hi,

echo $java_home # does not yeild the correct result
echo $weblogic_home # yeilds the correct result.

From the below output

Code:
     bea 15160 15144  0  Feb 20  ?        52:49 /opt/jdk150_07/bin/IA64N/java -Dplatform.home=/opt/bea/weblogic92 -Dwls.home=/opt/bea/weblogic92/server -Djava.security.policy=

echo $java_home yeilds "-Djava.security.policy=" instead of "/opt/jdk150_07/bin/IA64N/java"

The best string to grep for the correct java could be to grep using keyword "bin" and "/java".
Also, when i copy paste it in my main script, i get the below error.

Code:
 
./master_script.sh[27]: Syntax error at line 78 : `=~' is not expected.

Kindly help.

Last edited by mohtashims; 02-28-2013 at 10:51 AM..
# 11  
Old 02-28-2013
That is because it assigned the last occurrence of pattern: java

Replace [[ $t =~ java ]] with [[ $t =~ /java ]]

I hope this helps.
# 12  
Old 02-28-2013
Quote:
Originally Posted by bipinajith
That is because it assigned the last occurrence of pattern: java

Replace [[ $t =~ java ]] with [[ $t =~ /java ]]

I hope this helps.
It does help.

It works when I create a new script file and copy-paste your code.

But, when i copy paste it in my existing script the same code, i get the below error.

Code:
 
./master_script.sh[27]: Syntax error at line 78 : `=~' is not expected.

I have HP-UX

Kindly help.

Last edited by mohtashims; 02-28-2013 at 11:28 AM..
# 13  
Old 02-28-2013
OK, then replace existing for loop with:
Code:
for t in $o
do
        if echo "$t" | grep -q "/java"
        then
                java_home="$t"
        fi
        if echo "$t" | grep -q "\-Dplatform\.home"
        then
                weblogic_home="${t#-Dplatform.home=}"
        fi
done

OR
Code:
for t in $o
do
        $( echo "$t" | grep -q "/java" )  && java_home="$t"
        $( echo "$t" | grep -q "\-Dplatform\.home" ) && weblogic_home="${t#-Dplatform.home=}"
done

This User Gave Thanks to Yoda For This Post:
# 14  
Old 02-28-2013
Quote:
Originally Posted by bipinajith
OK, then replace existing for loop with:
Code:
for t in $o
do
        if echo "$t" | grep -q "/java"
        then
                java_home="$t"
        fi
        if echo "$t" | grep -q "\-Dplatform\.home"
        then
                weblogic_home="${t#-Dplatform.home=}"
        fi
done

OR
Code:
for t in $o
do
        $( echo "$t" | grep -q "/java" )  && java_home="$t"
        $( echo "$t" | grep -q "\-Dplatform\.home" ) && weblogic_home="${t#-Dplatform.home=}"
done

Thanks a Ton!!
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