The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search for string in a file and extract another string to a variable daikeyang Shell Programming and Scripting 6 03-20-2009 08:45 PM
extract a string from main string madhu.it Shell Programming and Scripting 1 10-06-2008 05:05 AM
extract a sub string from a main string madhu.it Shell Programming and Scripting 5 10-04-2008 03:22 AM
Extract string between <> rakeshou Shell Programming and Scripting 14 11-21-2007 01:10 PM
How to extract a portion of a string from the whole string ds_sastry UNIX for Dummies Questions & Answers 2 09-29-2001 11:40 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 06-09-2009
mglenney mglenney is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 85
Looking for a better way to extract a string

This is a question about optimization. I can do what I want but the users of this forum always find a way to do it better and I end up learning from it.

We have resin application servers. I want to extract a variable from the running processes:


Code:
[me]$ ps aux | grep java
resin    15212 19.8 10.9 3220756 1797684 ?     Sl   Jun04 1554:10 /usr/java/default/bin/java -Xms2304m -Xmx2304m -XX:NewRatio=8 -XX:+HeapDumpOnOutOfMemoryError -XX:PermSize=128m -XX:MaxPermSize=128m -DjiveHome=/opt/jiveHome-inst01 -Dhostname=blah -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -Dtangosol.coherence.machine=blah -Dtangosol.coherence.member=inst01 -Dtangosol.coherence.localhost=10.17.21.167 -Dtangosol.coherence.localport=16000 -Dtangosol.coherence.clusterport=24211 -Dtangosol.coherence.clusteraddress=224.2.4.0 -Dtangosol.coherence.log.level=9 -Dcom.sun.jndi.ldap.connect.pool.timeout=120000 -Dcom.sun.management.jmxremote.port=30001 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Doracle.net.tns_admin=/opt/oracle/network/admin -Dc3p0.maxIdleTime=600 -Dnntp.ip=10.17.21.167 -Dnntp.listen.port=8089 -Xss128k -Dresin.home=/opt/resin-pro-3.0.21-inst01 -Dserver.root=/opt/resin-pro-3.0.21-inst01 -Djava.util.logging.manager=com.caucho.log.LogManagerImpl -Djavax.management.builder.initial=com.caucho.jmx.MBeanServerBuilderImpl com.caucho.server.resin.Resin -socketwait 53858
resin    15214 19.7 11.8 3217244 1945076 ?     Sl   Jun04 1541:40 /usr/java/default/bin/java -Xms2304m -Xmx2304m -XX:NewRatio=8 -XX:+HeapDumpOnOutOfMemoryError -XX:PermSize=128m -XX:MaxPermSize=128m -DjiveHome=/opt/jiveHome-inst02 -Dhostname=blah -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -Dtangosol.coherence.machine=blah -Dtangosol.coherence.member=inst01 -Dtangosol.coherence.localhost=10.17.21.168 -Dtangosol.coherence.localport=16000 -Dtangosol.coherence.clusterport=24211 -Dtangosol.coherence.clusteraddress=224.2.4.0 -Dtangosol.coherence.log.level=9 -Dcom.sun.jndi.ldap.connect.pool.timeout=120000 -Dcom.sun.management.jmxremote.port=30002 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Doracle.net.tns_admin=/opt/oracle/network/admin -Dc3p0.maxIdleTime=600 -Dnntp.ip=10.17.21.168 -Dnntp.listen.port=8089 -Xss128k -Dresin.home=/opt/resin-pro-3.0.21-inst02 -Dserver.root=/opt/resin-pro-3.0.21-inst02 -Djava.util.logging.manager=com.caucho.log.LogManagerImpl -Djavax.management.builder.initial=com.caucho.jmx.MBeanServerBuilderImpl com.caucho.server.resin.Resin -socketwait 33796
17814    26011  0.0  0.0  61140   712 pts/3    S+   10:47   0:00 grep java

I'm looking to extract the bold part of that, Dserver.root. It won't always be the same info after Dserver.root= but I will always need all the information between the equal sign and the trailing space.

Here's how I did it:


Code:
[me]$ ps aux | grep java | tr ' ' '\n' | grep Dserver.root | awk -F= '{ print $2 }'
/opt/resin-pro-3.0.21-inst01
/opt/resin-pro-3.0.21-inst02

That works but I'm sure I'm piping too much or some whiz can come along and say "I can name that string in 10 characters". I learn a lot that way. Or, maybe, you can just say "WOW. What an awesome solution to that problem. You are truly one of the greatest this forum has ever seen. Do you sell t-shirts with your face on them?"

(EDIT) Do I need to add my own line breaks to code blocks to keep them from extending out like these did?(/EDIT)

Thanks,

Mike G.

Last edited by mglenney; 06-09-2009 at 03:17 PM..
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:39 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0