Extract version number from a string

Following Kent’s answers, this can work:

grep -Po '(?<=divider-bin-)\d.\d.\d'

and even better:

grep -Po '(?<=divider-bin-)[^;]+'

it greps from divider-bin- until it find the ; character. This way any NNN.NNN. ... . NNN format will work (no matter how many blocks of NN).

Test:

$ echo "data-c(kuh-small1);divider-bin-1.4.4;divider-conf-1.3.3-w(1,16);storage-bin-1.5.4;storage-conf-1.5.0-w(1);worker-bin-4.5.1;worker-conf-4.4.1-c(kuh)-win2" | grep -Po '(?<=divider-bin-)[^;]+'
1.4.4
$ echo "data-c(kuh-small1);divider-bin-1.4;divider-conf-1.3.3-w(1,16);storage-bin-1.5.4;storage-conf-1.5.0-w(1);worker-bin-4.5.1;worker-conf-4.4.1-c(kuh)-win2" | grep -Po '(?<=divider-bin-)[^;]+'
1.4

Leave a Comment