我有一个包含以下内容的文本文件
<?xml version="1.0" encoding="UTF-8"?> <slave> <name>slave1</name> <description>00.000.000.00</description> <remoteFS>/home/<dir>/</remoteFS> <numExecutors>8</numExecutors> <mode>NORMAL</mode> <retentionStrategy class="hudson.slaves.RetentionStrategy$Always"/> <launcher class="hudson.plugins.sshslaves.SSHLauncher" plugin="ssh-slaves@1.25.1"> <host>00.000.000.00</host> <port>9192</port> <credentialsId>xxxxx-xxxx-xxxxxx</credentialsId> <javaPath>/usr/bin/java</javaPath> <maxNumRetries>0</maxNumRetries> <retryWaitTime>0</retryWaitTime> <sshHostKeyVerificationStrategy class="hudson.plugins.sshslaves.verifiers.NonVerifyingKeyVerificationStrategy`"/> </launcher> <label>xxxxx</label> <nodeProperties> <hudson.slaves.EnvironmentVariablesNodeProperty> <envVars serialization="custom"> <unserializable-parents/> <tree-map> <default> <comparator class="hudson.util.CaseInsensitiveComparator"/> </default> <int>4</int> <string>CTS_HOME</string> <string>xxxx</string> <string>xxxxx</string> <string>xxxxx</string> <string>PYTHONPATH</string> <string>/home/<dir></string></tree-map> </envVars> </hudson.slaves.EnvironmentVariablesNodeProperty> </nodeProperties> </slave>`
我想要整个文件中的值<launcher class="hudson.plugins.sshslaves.SSHLauncher"
,但是我无法获得此值
此外,詹金斯奴隶使用的不同启动方法的hudson.plugins.sshslaves.SSHLauncher
值也不同
如何仅获取启动器类的值? 这是我到目前为止尝试过的,
cat text_file | sed -nr 's/.*launcher="([^"]+)".*/\1/p'
cat text_file | sed -n 's:.*<launcher>\(.*\)</launcher>.*:\1:p'
cat text_file | grep -o '<launcher>.*</launcher>'
但是这3个都不起作用。 有人可以帮我吗?
答案 0 :(得分:1)
是这里:
sed -n 's:.*<launcher class="\(.*\)" plugin=".*">.*</launcher>.*:\1:p' text_file
它应该输出:
hudson.plugins.sshslaves.SSHLauncher