Extract data between to points

August 19, 2009 at 08:30:14
Specs: Windows XP
I wish to look in a directory at all the .txt files and extract the lines within the file that starts with A10:@.

Utilmatley I really only want the first 16 characters after the @ symbol not the entire line. The 17th character after the @ is always a * so I could just extract and write to a file the data between A10:@ and *.

The input file has lines which are similair to

C36: 0.00C35: 2.00C34: 7.00C39: 0.00C38:
A10:@+.1803 +.0221 *SKIP *SKIP
C36: 0.00C35: 2.00C34: 7.00C39: 0.00C38:
A10:@+.1798 +.0221 *SKIP *SKIP

The output should look like this

+.1803 +.0221
+.1798 +.0221

The following code almost worked

@echo off > newfile.txt & setLocal enableDELAYedexpansion
for /f "tokens=1,2* delims= " %%i in ('FINDSTR "A10:@" *.txt') do (echo %%i %%j >> newfile.txt)


the above code outputted

file1.txt:A10:@+.1803 +.0221
file2.txt:A10:@+.1798 +.0221

which is almost correct. It appened the file name to the front of the row. So now I need to extract the first variable stating at 16 for a length of 6.

I thought I can now use the call set %var to strip the first portion out something like the following

@echo off > newfile.txt & setLocal enableDELAYedexpansion
for /f "tokens=1,2* delims= " %%i in ('FINDSTR "A10:@" *.txt') do (call set substring=%%i:~16,6%%
echo %substring% %%j >> newfile.txt)

This generated the following


The code alomost worked but it lost the first variable substring all together. I muist be using the call set substring wrong.

Please help, and thanks in advance,


See More: Extract data between to points

Report •

August 19, 2009 at 13:49:42
No need to use substrings, the for loop is able to take care of it in this case.

"tokens=1* delims=@" %%i in ('FINDSTR /b "A10:@" *.txt')

Use %%j.

Report •

August 24, 2009 at 05:17:41
Thanks for yor help. I tried a variety of code using what you stated. Every version except one did not have anything in the resualnt file. The one that was different had the entire line after the @ symbol. Recall all I want is the first two columns. However only the portion after the @ symbol on the first line.

Input data
A10:@+.1803 +.0221 *SKIP *SKIP

I only want
+.1803 +.0221

Please help again...

Report •

August 25, 2009 at 13:23:04
Hi Fro-Dawg

This what you want

@echo off
for /f "tokens=1-3 delims=@*" %%a in (Data.txt) do (
if "%%a" EQU "A10:" echo %%b
) >> New.txt

Report •

Related Solutions

August 27, 2009 at 07:38:46

Thanks for your help that is excatly what I was looking for, for one file; however I was trying to do this to all the files in the current subdirectory that has a txt extension. I tried to added " > new.txt & setLocal enableDELAYedexpansion" after the echo statement and changed "data.txt" to "*.txt" as I had in an earlier attempts but it did not work The system cannot find the file *.txt came across the screen. And there was nothing in the "new.txt" file.

Could you please help again.

thanks in advance,


Report •

August 27, 2009 at 16:53:35
Hi Fro-Dawg
This what you want
I given the file the extension .dat so it do'es not get picked up by the first for loop.
You can rename later if required.

@echo off
type nul > new.dat
for %%a in (*.txt) do (
for /f "tokens=1-3 delims=@*" %%b in ('type "%%a"') do (
if "%%b" EQU "A10:" echo %%c >> new.dat

Report •

September 1, 2009 at 04:31:16
Yes Dtech10 this is excatly what I needed thank you very much!!

Report •

Ask Question