1

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.

Community
  • 1
  • 1
Daniella
  • 171
  • 2
  • 3
  • 14
  • 1
    Why don't you use PowerShell or write a small console C# application to do it for you? – Riaan Jul 28 '14 at 20:00
  • I don't know what PowerShell is, but I have a batch file that runs curl. Since I can't get libcurl to run on my computer I can't use C# or C++. – Daniella Jul 28 '14 at 20:03
  • @riaandelange I just read a little bit about Powershell and this looks like exactly what I'm looking for. Thank you – Daniella Jul 28 '14 at 20:39

2 Answers2

2
FINDSTR /b "[0-9]" q25003233.txt

I used a file named q25003233.txt containing your data for my testing.

Magoo
  • 77,302
  • 8
  • 62
  • 84
1
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

MC ND
  • 69,615
  • 8
  • 84
  • 126
  • Wow it is possible! I'm guessing if I substitute `[0-9]` with `[a-z]` I can get the lines without numbers separately! Thanks so much. – Daniella Jul 28 '14 at 20:49