Reputation: 181
I'm not sure if this is possible, but is there a way for a batch file to read a text file, but skip lines that do not start with a number?
For example:
handled
219278
check
219276
control
219274
co
219268
Can a for loop skip handled, check, control, etc.?
I know this:
cscript C:\Users\c1921\Test\curltest.vbs"!$MyVar!">>C:\Users\c1921\Test\Datapoints\!$MyVar!.txt
Will put all output to this text file but this:
FOR /F %%i in (C:\Users\c1921\Test\Datapoints\!$MyVar!.txt) DO (
set "$UnitID=%%i"
)
Reads every line into a variable. Can I somehow use delims and tokens to only get the numbers?
Edit:
I thought this might be possible going off of an answer on this question: Windows Batch file to echo a specific line number
The file I have on occassion might not have a number between the words for example:
handled
check
219276
control
219274
co
219268
This should not happen often, but I'd like to make sure I can avoid this when it does.
Upvotes: 1
Views: 2742
Reputation: 79982
FINDSTR /b "[0-9]" q25003233.txt
I used a file named q25003233.txt
containing your data for my testing.
Upvotes: 2
Reputation: 70923
for /f "delims=" %%a in ('findstr /r /b /c:"[0-9]" "c:\somewhere\file.txt"') do echo %%a
This uses findstr
to filter the input file with a regular expresion , returning only lines that start with a number
Upvotes: 1