I need to parse some info out of a big nasty ps string. I need to get the username and PID, then the /usr/user/java.instanceName/ part into one line.
I tried grep, sed and awk, but I dont know any of them that well. And after hours of reading for this simple task, I’m hoping someone can just tap out a quick one liner.
This is the last thing I tried before asking:
ps auxwww | sed 's/^[a-z]* *[0-9]*//g;s/\/usr\/user\/[a-z._0-9]*//g'
Here is the std out from the ps auxwww command:
root 3837 2.5 32.5 4697784 2657720 ? Sl Sep13 30:23
/usr/java/jdk16/bin b.WebService.port=80
-Dorg.jboss.naming.NamingService.port=90 -Dorg.jboss.na mi.port=90 -Dorg.jboss.invocation.jrmp.server.JRMPInvoker.port=40
-Dorg.jbos server.PooledInvoker.port=41 -Dorg.jboss.remoting.transport.Connector.port=42 ing.transport.Connector.messaging.port=180
-Dorg.jboss.remoting.transport.Conn 1 -Djboss.bind.address=10.0.0.1 -Dtomcat.bind.address=10.0.0.1 -Dtomca cat.https.port=443 -Djava.net.preferIPv4Stack=true
che.cluster.name=cluster =INVALIDATION_ASYNC
cache.mcast.port=457 -Dejb3.cache.mode=LOCAL
-Dejb3.cache.cluster.name=EJB3-en ss.platform.mbeanserver
-Djavax.management.builder.initial=org.jboss.system.serv ilderImpl -server -Dsun.security.ssl.allowUnsafeRenegotiatio
ed.dirs=/usr/user/java.instanceName/lib/endorsed
-Dsun.rmi.dgc.client.gcInte mi.dgc.server.gcInterval=3600000
-Djavax.net.ssl.trustStore=/usr/java/jdk16/jre/ -Djavax.net.ssl.trustStorePassword=pass123 -Djavax.net.ssl.trustStoreType=JKS pGC -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -XX:+UseParNewG m -XX:PermSize=512m -XX:MaxPermSize=512m -jar run.jar -c jvmname -b 10.0.1.1
I think this should work:
That breaks down like this:
sed -nturns off the default print action on every line;/java.instanceName/will pick only lines that have that pattern in it; thescommand uses;as a delimiter because/is used later in the pattern;\(^[a-z]* *[0-9]*\)is as you had it and matches the user and PID at the beginning of the line, but with the additional effect of saving exactly what was matched; then we skip everything up until\(/usr/user/...[A-Za-z._0-9/]*\)which matches a path prefixed by/usr/user/(I tweaked the character class to include uppercase and the/) – that is saved for future use; finally the space after that path and everything else are matched. The;\1 \2;ppart replaces the entire match with the two sub-parts we saved and prints it out.