Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 toC36: 0.00C35: 2.00C34: 7.00C39: 0.00C38:
A10:@+.1803 +.0221 *SKIP *SKIP
D;0:@+.000
C36: 0.00C35: 2.00C34: 7.00C39: 0.00C38:
A10:@+.1798 +.0221 *SKIP *SKIP
D;0:@+.000000+.000000+.000000The output should look like this
+.1803 +.0221
+.1798 +.0221The 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 +.0221which 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
+.0221
+.0221The 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,
Fro

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.

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 *SKIPI only want
+.1803 +.0221Please help again...

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
]

dtech10,
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,
Fro-dawg

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
))

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |