我有 pom.xml:
<scm>
<developerConnection>scm:git:ssh://[email protected]:anton_patsev/maven-release-example3.git</developerConnection>
<tag>HEAD</tag>
</scm>
如何获取字符串[电子邮件受保护]:来自 pom.xml 的 anton_patsev/maven-release-example3.git?
谢谢!
答案1
string=$(cat pom.xml | grep developerConnection | sed -e s/\<developerConnection\>scm:git:ssh://g)
echo string
echo $string
developerConnection=$(echo ${string//[[:blank:]]/} | cut -c 3- | sed s/developerConnection//g | head -c-4)
echo developerConnection
developerConnection=$(echo $developerConnection| sed 's/gitlab.tools.russianpost.ru\//gitlab.tools.russianpost.ru:/g')
echo developerConnection
答案2
正则表达式应该不是用于解析 xml/html 数据。标记数据没有“义务”将标签或内容文本保留在单行上。
使用适当的 xml/html 解析器,例如xmllint
或xmlstarlet
:
$ xmllint --xpath 'scm/developerConnection/text()' pom.xml
scm:git:ssh://[email protected]:anton_patsev/maven-release-example3.git