My task is to grab latest version of maven in bash script using curl https://apache.osuosl.org/maven/maven-3/ Output should be: 3.8.5
CodePudding user response:
One way is to
- Use grep to only get the lines containing the
folderlink - Use sed with an regex to get only the version number
- Use
sortto sort the lines - Use
tail -n1to get the last line
curl -s https://apache.osuosl.org/maven/maven-3/ \
| grep folder \
| gsed -E 's/.*([[:digit:]]\.[[:digit:]]\.[[:digit:]]).*/\1/' \
| sort \
| tail -n1
Output:
3.8.5
CodePudding user response:
Using sed and tac
-sin curl command to silence outputtacreverse order of file/^<img src/{s/\([^>]*>\)\{2\}\([^/]*\).*/\2/p;:a;n;ba}Match lines starting with<img srcthen extract the first match
$ curl -s https://apache.osuosl.org/maven/maven-3/ | tac | sed -n '/^<img src/{s/\([^>]*>\)\{2\}\([^/]*\).*/\2/p;:a;n;ba}'
3.8.5
