我正在尝试从中提取最新版本的谷歌应用引擎他们的目录。为此,我使用 curl + awk。我发现以下正则表达式提取了我需要的内容:/featured\/google_appengine_(.*?)\.zip/g
,但是当我尝试在里面使用它时:
curl -s https://storage.googleapis.com/appengine-sdks/ | awk '/featured\/google_appengine_(.*?)\.zip/'
我得到了全文,但没有featured/google_appengine_1.9.17.zip
,当我将其更改为
curl -s https://storage.googleapis.com/appengine-sdks/ | awk '/featured\/google_appengine_(.*?)\.zip{ print $1}/'
我什么都没得到。有人能指出我的错误吗?
答案1
此脚本摘录全部featured/google_appengine
按字母顺序排列的条目:
curl -s https://storage.googleapis.com/appengine-sdks/ | awk -F "featured/google_appengine_" '{ for (i = 2; i <= NF; i++) print $i }' | awk -F "<" '{print echo "featured/google_appengine_"$1}' | sort
例如:
featured/google_appengine_1.9.18.zip
featured/google_appengine_1.9.19.zip
如果您需要最新版本,请使用以下命令:
curl -s https://storage.googleapis.com/appengine-sdks/ | awk -F "featured/google_appengine_" '{ for (i = 2; i <= NF; i++) print $i }' | awk -F "<" '{print echo "featured/google_appengine_"$1}' | sort | tail -1
例如:
featured/google_appengine_1.9.19.zip
答案2
“featured/google_appengine_1.9.17.zip” 是您想要的吗?试试这个快速而简单的解决方案:
curl -s https://storage.googleapis.com/appengine-sdks/ | awk -F "featured/google_appengine_" '{print $2}' | awk -F "<" '{print echo "featured/google_appengine_"$1}'