I'm trying to get a spacific changing string form a site.
I used the commend:
wget -qO - www.factorio.com/download | grep '/get-download
the output is:
wget -qO - www.factorio.com/download | grep '/get-download'
<p>If you are running a server, you can use <a href="https://factorio.com/get-download/stable/headless/linux64">this link</a> to always download the latest stable version.
<a href="/get-download/1.1.110/headless/linux64"
<a href="/get-download/1.1.110/demo/win64-manual"
<a href="/get-download/1.1.110/demo/win64"
<a href="/get-download/1.1.110/demo/osx"
<a href="/get-download/1.1.110/demo/linux64"
I need to get the 1.1.110 from the line:
<a href="/get-download/1.1.110/headless/linux64"
can be longer and can be shorter. but the /get-download/XXXXX/headless/linux64
is fixed.
grep
is not the correct tool for extracting information from HTML/XML, but it's sufficient in your case.This matches texts that start with
/get-download/
and then contain something somewhat looking like a version number based on numbers and dots.uniq
is required, because multiple version lines will be returned. The-o
flag letsgrep
return only matches and<?=
will throw away thedownload
text after matching.This is the result:
1.1.110
Using any version of
sed
:or any version of
grep
andcut
:or GNU
awk
for the 3rd arg tomatch()
: