I have a bunch of data text files stored somewhat like this,
Characteristics of the text: identifiers may repeat, the length of each piece of data is not fixed, and the units for each kind may not necessarily be the same.
I want to find the data on the line below Separator in this kind of data text and append it to a file.
My idea is to first determine the line number X of Separator, read line X+1, and extract the needed data. Since I'm a newbie, after reading those posts in the sticky index I'm still kind of confused. The batch file I wrote below is also pretty clumsy, and it still has some problems: for example, if the data length changes, there's no way to record it accurately!
I don't know which expert could help point me in the right direction and optimize this a bit.
[ Last edited by 29984365 on 2007-4-6 at 06:12 PM ]
Identifier a: 1111 units
There may be N identifiers in between
Identifier b: 222 units
Separator
Identifier c: 333 units
Identifier c: 4444 units
Identifier d: 55 units
Characteristics of the text: identifiers may repeat, the length of each piece of data is not fixed, and the units for each kind may not necessarily be the same.
I want to find the data on the line below Separator in this kind of data text and append it to a file.
My idea is to first determine the line number X of Separator, read line X+1, and extract the needed data. Since I'm a newbie, after reading those posts in the sticky index I'm still kind of confused. The batch file I wrote below is also pretty clumsy, and it still has some problems: for example, if the data length changes, there's no way to record it accurately!
@echo off
setlocal
for /f "tokens=1,* delims=:" %%a in ('findstr /n /c:"分隔符" test.txt') do (
set line=%%a
)
set num=0
setlocal enabledelayedexpansion
for /f "skip=%line% delims=" %%i in (test.txt) do (
set /a num+=1
set var=%%i
if !num! equ 1 echo !var:~7,3!>>num.txt
)
endlocal
I don't know which expert could help point me in the right direction and optimize this a bit.
[ Last edited by 29984365 on 2007-4-6 at 06:12 PM ]
