在shell脚本

时间:2016-09-07 14:09:44

标签: shell

我正在尝试从输出中提取一段文本。不知怎的,我的正则表达式是在notepad ++中工作但不在shell中。

这是输出:

-Duser.instal-Djava.library.path=/apps/WebSphere/AppServer85i2/lib/native/aix/ppc_64/:/app
s/WebSphere/AppServer85i2/java/jre/lib/ppc64/compressedrefs:/apps/WebSphere/AppServer85i2/java/jre/lib/ppc64:/apps/WebSphere/AppServer85i2/java/jre/lib/ppc64:/apps/WebSphere/Ap
pServer85i2/java/jre/lib/ppc64/compressedrefs:/apps/WebSphere/AppServer85i2/java/jre/lib/ppc64/j9vm:/apps/WebSphere/AppServer85i2/java/jre/lib/ppc64:/apps/WebSphere/AppServer85
i2/java/jre/../lib/ppc64:/apps/WebSphere/AppServer85i2/bin:/apps/WebSphere/AppServer85i2/nulldllsdir:/usr/lib:/usr/lib: -Djava.endorsed.dirs=/apps/WebSphere/AppServer85i2/endor
sed_apis:/apps/WebSphere/AppServer85i2/java/jre/lib/endorsed -Duser.install.root=/apps/WebSphere/profiles85i2/node -Djava.security.auth.login.config=/apps/WebSphere/profiles85i2/node/properties/wsjaas.conf -Djava.security.policy=/
apps/WebSphere/profiles85i2/node/properties/server.policy com.ibm.wsspi.bootstrap.WSPreLauncher -nosplash -application com.ibm.ws.bootstrap.WSLauncher com.ibm.ws.runtime.WsServ
er /apps/WebSphere/profiles85i2/node/config hello hello2 PROJ1_LSDS-1
    root 2057l -Dcom.ibm.xtq.processor.overrideSecureProcessing=true -Xbootclasspath/p:/apps/WebSphere/AppSer
ver85i2/java/jre/lib/ibmorb.jar -classpath /apps/WebSphere/profiles85i2/node/properties:/apps/WebSphere/AppServer85i2/properties:/apps/WebSphere/AppServer85i2/lib/startup.jar:/
apps/WebSphere/AppServer85i2/lib/bootstrap.jar:/apps/WebSphere/AppServer85i2/lib/jsf-nls.jar:/apps/WebSphere/AppServer85i2/lib/lmproxy.jar:/apps/WebSphere/AppServer85i2/lib/url
protocols.jar:/apps/WebSphere/AppServer85i2/deploytool/itp/batchboot.jar:/apps/WebSphere/AppServer85i2/deploytool/itp/batch2.jar:/apps/WebSphere/AppServer85i2/java/lib/tools.ja
r -Dibm.websphere.internalClassAccessMode=allow -Xms50m -Xmx256m -Xcompressedrefs -Xscmaxaot4M -Xscmx90M -Dws.ext.dirs=/apps/WebSphere/AppServer85i2/java/lib:/apps/WebSphere/pr
ofiles85i2/node/classes:/apps/WebSphere/AppServer85i2/classes:/apps/WebSphere/AppServer85i2/lib:/apps/WebSphere/AppServer85i2/installedChannels:/apps/WebSphere/AppServer85i2/li
b/ext:/apps/WebSphere/AppServer85i2/web/help:/apps/WebSphere/AppServer85i2/deploytool/itp/plugins/com.ibm.etools.ejbdeploy/runtime -Dderby.system.home=/apps/WebSphere/AppServer
85i2/derby -Dcom.ibm.itp.location=/apps/WebSphere/AppServer85i2/bin -Djava.util.logging.configureByServer=true -Duser.install.root=/apps/WebSphere/profiles85i2/node -Djava.ext.
dirs=/apps/WebSphere/AppServer85i2/tivoli/tam:/apps/WebSphere/AppServer85i2/java/jre/lib/ext -Djavax.management.builder.initial=com.ibm.ws.management.PlatformMBeanServerBuilder
 -Dpython.cachedir=/apps/WebSphere/profiles85i2/node/temp/cachedir -Dwas.install.root=/apps/WebSphere/AppServer85i2 -Djava.util.logging.manager=com.ibm.ws.bootstrap.WsLogManage
r -Dserver.root=/apps/WebSphere/profiles85i2/node -Dcom.ibm.security.jgss.debug=off -Dcom.ibm.security.krb5.Krb5Debug=off -Dcom.interwoven.livesite.fileappender.root=/apps/WebS
phere/profiles85i2/node/logs/PROJ1PP_LSDS-1 -Dlog4j.configuration=log4j.xml -Dlog4j.debug=true -Djava.library.path=/apps/WebSphere/AppServer85i2/lib/native/aix/ppc_64/:/apps/We
bSphere/AppServer85i2/java/jre/lib/ppc64/compressedrefs:/apps/WebSphere/AppServer85i2/java/jre/lib/ppc64:/apps/WebSphere/AppServer85i2/java/jre/lib/ppc64:/apps/WebSphere/AppSer
ver85i2/java/jre/lib/ppc64/compressedrefs:/apps/WebSphere/AppServer85i2/java/jre/lib/ppc64/j9vm:/apps/WebSphere/AppServer85i2/java/jre/lib/ppc64:/apps/WebSphere/AppServer85i2/j
ava/jre/../lib/ppc64:/apps/WebSphere/AppServer85i2/bin:/apps/WebSphere/AppServer85i2/nulldllsdir:/usr/lib:/usr/lib:

所以我在寻找:" -Duser.install.root="参数,我想提取值:" /apps/WebSphere/profiles85/node"。

输出中有2个。我必须采用一条路径并将其传递给另一个脚本。我用来提取我想要的文本的正则表达式。

&#34 - Duser.install.root=([\/\w\/]+?)"这个正则表达式在记事本中有效。

但我无法在shell脚本中检索文本。我希望我很清楚。

提前感谢您的回答。

1 个答案:

答案 0 :(得分:0)

使用sed:

$ sed -n "s/.*-Duser.install.root=\([^ ]*\).*/\1/p" file | uniq
/apps/WebSphere/profiles85i2/node
shell脚本中的

res=$(sed -n "s/.*-Duser.install.root=\([^ ]*\).*/\1/p" file | uniq)
echo "$res"

输出:

/apps/WebSphere/profiles85i2/node
相关问题