Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Parsing 使用sed或awk获取标记之间的路径_Parsing_Sed_Awk - Fatal编程技术网

Parsing 使用sed或awk获取标记之间的路径

Parsing 使用sed或awk获取标记之间的路径,parsing,sed,awk,Parsing,Sed,Awk,我想从ps输出获取路径(/tmp/deployment/deployment/hostVBox\u 8080\u GSA/): username@hostVBox:~$ps ax |grep jboss 16291 pts/4 Sl 0:34 java -Dprogram.name=run.sh -Xms128m -Xmx512m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600

我想从ps输出获取路径(/tmp/deployment/deployment/hostVBox\u 8080\u GSA/):

username@hostVBox:~$ps ax |grep jboss
16291 pts/4    Sl     0:34 java -Dprogram.name=run.sh -Xms128m -Xmx512m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djava.endorsed.dirs=/tmp/deployment/deployment/hostVBox_8080_GSA/lib/endorsed -classpath /tmp/deployment/deployment/hostVBox_8080_GSA/bin/run.jar:/lib/tools.jar org.jboss.Main
我该怎么做

溴 Kolesar

试试:

命令:

awk -F"dirs=" '
    /java/{
        a=$2
        split(a,path," -")
        sub(/[^/]*\/[^/]*$/,"",path[1])
        print path[1]
    }'

这可能适合您:

echo "a bunch of stuff ... -classpath /tmp/deployment/deployment/hostVBox_8080_GSA/bin/run.jar:/lib/tools.jar org.jboss.Main' |
sed -e 's#.*-classpath \(\([^/]*/\)*\)bin/run.jar.*#\1#'
/tmp/deployment/deployment/hostVBox_8080_GSA/

试试这个,看看它是否有效:

ps ax |grep jboss|awk -F'java.endorsed.dirs=' '{gsub(/lib.*/,"",$2);print $2;exit;}'