mercredi 30 avril 2014

extract a base directory from the output of ps


Vote count:

0




I am looking to extract a basedir from the output of ps -ef | grep classpath myprog.jar



root 20925 20886 1 17:41 pts/0 00:01:07 /opt/myprog/java/jre/bin -classpath myprog.jar


java is always a sub-dir under the basedir but the install path can vary from server to server e.g.


/usr/local/myprog/java/jre/bin


/opt/test/testing/myprog/java/jre/bin


So once i have my string how do I extract everything from before java until the beginning of the path ? i.e /opt/myprog


thanks



asked 1 min ago

eramm

114

1 Answer



Vote count:

0




Using grep -P:



grep -oP '\S+(?=/java)' <<< "$s"
/opt/myprog


answered 4 secs ago





Aucun commentaire:

Enregistrer un commentaire