我想從輸出中提取一段文本。不知何故,我的正則表達式在記事本++中工作,但不在shell中。提取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個。我必須採取一條路徑並將其傳遞給另一個腳本。我用於提取我想要的文本的正則表達式。
「 - Duser.install.root=([\/\w\/]+?)
」這個正則表達式在記事本中工作。
但我無法實現在shell腳本中檢索文本。我希望我很清楚。
在此先感謝您的答案。
你是如何嘗試和使用的外殼,正則表達式? –