Your pattern is a PCRE compliant regex, [\s\S]
matches any char in a PCRE pattern, but not with POSIX BRE regex flavor that you are using with your grep
since you did not use-P
option.
If you want to do it with GNU grep use
grep -oPm 1 'Version\s*:\s*\K\d+(?:\.\d+)+' *.txt
See this online demo
Details
Version
- Version
string
\s*:\s*
- a colon enclosed with 0+ whitespaces
\K
- match reset operator
\d+
- 1+ digits and then
(?:\.\d+)+
- 1 or more repetitions of .
and 1+ digits.
You may do that with awk
:
awk '/^Version : [0-9]+/{print $3; exit}' *.txt
See the online awk demo:
s="Text
Version : 3.4.0.0 xxx xxx xxx
More text
Version : 5.6.0.0 xxx xxx xxx"
awk '/^Version : [0-9]+/{print $3; exit}' <<< "$s"
# => 3.4.0.0
Details
^Version : [0-9]+
finds a line that starts with Version : <1 or more digits>
{print $3; exit}
outputs the value of Field 3 and stops processing getting you just the first match.