Much better, though that should give you two lines of output since 0.27.0 appears twice in your source. If you want only one then you need to figure out rules for how to choose which one you want.
Also, your pattern might give the wrong result if the source includes something like the following: 1234.567.8901
Your code will yield 234.567.890 - I doubt that would be a correct result. Maybe not a problem, but you should always consider the possibility of outliers and plan accordingly.
Note that [0-9] can more easily be represented as \d
If you assume that you always want to extract from the title, then either of the following would work:
Code: Select all
call jrepl ".*title=\q(\d{1,3}\.\d{1,3}\.\d{1,3})\q.*" "$1" /xseq /f "line1.txt" /o "version.txt"
Code: Select all
call jrepl "title=\q(\d{1,3}\.\d{1,3}\.\d{1,3})\q" "$txt=$1" /xseq /jmatch /f "line1.txt" /o "version.txt"
There are other solutions, but those are the first two that popped into mind.
Or if you know your source only has one title, and you always want the entire title value, then:
Code: Select all
call jrepl ".*title=\q(.*?)\q.*" "$1" /xseq /f "line1.txt" /o "version.txt"
Code: Select all
call jrepl "title=\q(.*)\q" "$txt=$1" /xseq /jmatch /f "line1.txt" /o "version.txt"
I'm just guessing, but it looks like your line1.txt might be the first line of some larger file, and you did some preprocessing to extract the first line. If I'm correct, then you can work directly with the original file
Code: Select all
call jrepl ".*title=\q(.*?)\q.*" "$1" /xseq /inc 1 /f "original.txt" /o "version.txt"
Code: Select all
call jrepl "title=\q(.*)\q" "$txt=$1" /xseq /jmatch /inc 1 /f "original.txt" /o "version.txt"
If you want to get the value in an environment variable instead of a file, then remove the /O "VERSION.TXT" and add /RTN VERSION instead. The result will be in the VERSION variable when finished.
Dave Benham