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
folder
link - Use sed with an regex to get only the version number
- Use
sort
to sort the lines - Use
tail -n1
to 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
-s
in curl command to silence outputtac
reverse order of file/^<img src/{s/\([^>]*>\)\{2\}\([^/]*\).*/\2/p;:a;n;ba}
Match lines starting with<img src
then 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