Reputation: 3880
I am attempting to parse an output file for some data, and am having problems returning the value to my Windows shell.
What I am trying to do is simply return a value using a simple regular expression, and store that into my shell variable.
I currently have something like this:
%VAL% = %PERL% -e '$tmp="Value: 1000"; if ($tmp =~ /Value:\s(\d+)/) { print $1; }'
where %VAL%
is where I'd like to return what was found in $1
, and %PERL%
points to a local copy of perl.exe.
Can somebody please point out the proper way of doing this?
Upvotes: 1
Views: 125
Reputation: 1995
EDIT: It's a bit uglier than Unix:
for /f "tokens=*" %i in ('perl -e "$tmp=\"Value: 1000\"; if ($tmp =~ /Value:\s(\d+)/) { print $1; }"') do set VAL = %i
Or use set /p
with an intermediary file:
%PERL% -e '$tmp="Value: 1000"; if ($tmp =~ /Value:\s(\d+)/) { print $1; }' > file.txt
set /p VAL = < file.txt
del file.txt
Upvotes: 2