yum list 获取最后可用的包
yum list get last available package
我需要在存储库中提取最新可用包的子字符串
yum list myCompany-apps-MYPROJECT*
可用包
myCompany-apps-MYPROJECT-0.0.0.41-210409.noarch 1-160 myproject
myCompany-apps-MYPROJECT-0.0.0.42-210412.noarch 1-162 myproject
myCompany-apps-MYPROJECT-0.0.0.43-210412.noarch 1-163 myproject
myCompany-apps-MYPROJECT-0.0.0.44-210412.noarch 1-173 myproject
myCompany-apps-MYPROJECT-0.0.0.45-210412.noarch 1-174 myproject
myCompany-apps-MYPROJECT-0.0.0.46-210412.noarch 1-176 myproject
myCompany-apps-MYPROJECT-0.0.0.47-210412.noarch 1-179 myproject
myCompany-apps-MYPROJECT-1.0.0.1-210407.noarch 1-146 myproject
myCompany-apps-MYPROJECT-1.0.0.2-210407.noarch 1-147 myproject
myCompany-apps-MYPROJECT-1.0.0.3-210408.noarch 1-149 myproject
myCompany-apps-MYPROJECT-1.0.0.4-210408.noarch 1-150 myproject
我想提取 MYPROJECT 之后和日期时间之前的部分
我试过了:
function lastVersion () {
last_version=$(yum list myCompany-apps-MYPROJECT* | grep "myCompany-apps-MYPROJECT" | awk '{ print }'| awk -F "-" '{ print }' | sort -V | tail -1)
echo ${last_version}
}
输出是:1.0.0.4,我需要它是:0.0.0.47(第 2 列 (1-179) 中指示的最新一个,第 2 列究竟代表什么?)
非常感谢
用正则表达式提取你想要的数据和你想要排序的数据。然后在你要排序的数据上排序,把你感兴趣的数据去掉。
yum ... | grep "myCompany-apps-MYPROJECT" |
sed 's/.*-\([^-]*\)-[^ ]* *[0-9]*-\([0-9]*\).*/ /' |
sort -k2n | tail -n1 | cut -d' ' -f1
您可以使用 regexcrosswords ex 快速学习正则表达式。 https://regexcrossword.com/.
多合一 awk
脚本...
... | awk '!/myCompany-apps-MYPROJECT/ {next}
{sub("-",".",)}
max< {max=; split(,f,"-"); maxV=f[4]}
END {print maxV}' file
0.0.0.47
我需要在存储库中提取最新可用包的子字符串
yum list myCompany-apps-MYPROJECT*
可用包
myCompany-apps-MYPROJECT-0.0.0.41-210409.noarch 1-160 myproject
myCompany-apps-MYPROJECT-0.0.0.42-210412.noarch 1-162 myproject
myCompany-apps-MYPROJECT-0.0.0.43-210412.noarch 1-163 myproject
myCompany-apps-MYPROJECT-0.0.0.44-210412.noarch 1-173 myproject
myCompany-apps-MYPROJECT-0.0.0.45-210412.noarch 1-174 myproject
myCompany-apps-MYPROJECT-0.0.0.46-210412.noarch 1-176 myproject
myCompany-apps-MYPROJECT-0.0.0.47-210412.noarch 1-179 myproject
myCompany-apps-MYPROJECT-1.0.0.1-210407.noarch 1-146 myproject
myCompany-apps-MYPROJECT-1.0.0.2-210407.noarch 1-147 myproject
myCompany-apps-MYPROJECT-1.0.0.3-210408.noarch 1-149 myproject
myCompany-apps-MYPROJECT-1.0.0.4-210408.noarch 1-150 myproject
我想提取 MYPROJECT 之后和日期时间之前的部分
我试过了:
function lastVersion () {
last_version=$(yum list myCompany-apps-MYPROJECT* | grep "myCompany-apps-MYPROJECT" | awk '{ print }'| awk -F "-" '{ print }' | sort -V | tail -1)
echo ${last_version}
}
输出是:1.0.0.4,我需要它是:0.0.0.47(第 2 列 (1-179) 中指示的最新一个,第 2 列究竟代表什么?)
非常感谢
用正则表达式提取你想要的数据和你想要排序的数据。然后在你要排序的数据上排序,把你感兴趣的数据去掉。
yum ... | grep "myCompany-apps-MYPROJECT" |
sed 's/.*-\([^-]*\)-[^ ]* *[0-9]*-\([0-9]*\).*/ /' |
sort -k2n | tail -n1 | cut -d' ' -f1
您可以使用 regexcrosswords ex 快速学习正则表达式。 https://regexcrossword.com/.
多合一 awk
脚本...
... | awk '!/myCompany-apps-MYPROJECT/ {next}
{sub("-",".",)}
max< {max=; split(,f,"-"); maxV=f[4]}
END {print maxV}' file
0.0.0.47