0

I would like to extract version number from this string:

<a href="/url/version/tree/1.0.1alpha11" class="css-truncate">

Note that '/url/version/tree/' may change (ex: from /url/version/tree/ to /url/version2/tree1/) and version may change too (ex: from 1.01alpha11 to 2.0stable)

Ideas/suggestions?

0

sed solution:

Sample file input.txt:

<a href="/url/version/tree/1.0.1alpha11" class="css-truncate">
<a href="/url/version2/tree1/1.0.2alpha11" class="css-truncate">
<a href="/url/version/tree/2.0stable" class="css-truncate">

sed -En 's@.*\<href="/[^[:space:]]+/([^/"[:space:]]+).*@\1@p' input.txt

The output:

1.0.1alpha11
1.0.2alpha11
2.0stable
0

I extracted the version by using below awk command. As tested its worked fine.

Inputfile

<a href="/url/version/tree/1.0.1alpha11" class="css-truncate">
<a href="/url/version2/tree1/1.0.2alpha11" class="css-truncate">
<a href="/url/version/tree/2.0stable" class="css-truncate">

command

awk -F '[/]' '{print $NF}' Inputfile| awk -F '"' '{print $1}'

output

1.0.1alpha11
1.0.2alpha11
2.0stable
0

Source file: input.txt:

<a href="/url/version2/tree1/2.0stable" class="css-truncate">
<a href="/url/version/tree/1.0.1alpha11" class="css-truncate">
<a href="/url/version2/tree1/1.0.2alpha11" class="css-truncate">

Using awk and sed:

awk 'BEGIN { FS = "/" } { print $5 }' input.txt | sed -E 's/^(.*)"\s.*/\1/'

Results:

2.0stable
1.0.1alpha11
1.0.2alpha11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.