Reputation: 11
I need to search for a specific nubmer that comes after a string in a text file. For example I have this data:
yyy = 80rr, xxx = 136rr, zzz = 95rr
and i want to copy the numbers that between yyy
and rr
, xxx
and rr
, zzz
rr
.
Then I want to echo these numbers. Is it possible?
Upvotes: 1
Views: 151
Reputation: 67216
@echo off
for /F "delims=" %%a in (input.txt) do set "line=%%a"
set /A "%line:r=%"
echo yyyyyyy = %yyyyyyy%
echo xxxxxxx = %xxxxxxx%
echo zzzzzzz = %zzzzzzz%
For example:
C:\> type input.txt
yyyyyyy = 80rr, xxxxxxx = 136rr, zzzzzzz = 95rr
C:\> test.bat
yyyyyyy = 80
xxxxxxx = 136
zzzzzzz = 95
Upvotes: 0
Reputation: 79983
@ECHO OFF
SETLOCAL
FOR /f "tokens=3,7delims=r " %%a IN (q28193214.txt) DO (ECHO "%%a" and "%%b")
GOTO :EOF
I used a file named q28193214.txt
containing your data for my testing.
Upvotes: 1
Reputation: 749
What is your batch environmen? In an unix shell with awk this can be done easily:
echo "yyy = 80rr, xxx = 136rr, zzz = 95rr" |
awk '{ match($0, /yyy = ([0-9]*)rr, xxx = ([0-9]*)rr, zzz = ([0-9]*)rr/, a); print a[1] " " a[2] " " a[3]; }'
Upvotes: 0