Microsoft > Microsoft DOS

Finding multiple strings in a text file

<< < (2/4) > >>

Freerefill:
Nice! It's starting to work! Thank you very much, Dias!

So the 4-deep nested "FOR" loop proved to take a wee bit too long to process (I had enough time to wait, rethink, and edit the code into something that would work faster before it finished) so I re-worked it to three 2-deep nested loops:

REM Grab the first string in the first file
for /f "eol= tokens=1 delims=" %%a in (c:\fr1a.txt) do (
set /A var1=%%a+3
for /f "eol= tokens=1 delims=" %%b in (c:\fr2a.txt) do (
set /A var2=%%b+2
if "!var1!"=="!var2!" echo !var1!>> c:\for1.txt
)
)

for /f "eol= tokens=1 delims=" %%a in (c:\fr3a.txt) do (
set /A var1=%%a+1
for /f "eol= tokens=1 delims=" %%b in (c:\for1.txt) do (
set /A var2=%%b
if "!var1!"=="!var2!" echo !var1!>> c:\for2.txt
)
)

for /f "eol= tokens=1 delims=" %%a in (c:\fr4a.txt) do (
set /A var1=%%a
for /f "eol= tokens=1 delims=" %%b in (c:\for2.txt) do (
set /A var2=%%b
if "!var1!"=="!var2!" echo !var1!>> c:\for3.txt
)
)

Yes, the "d" was a typo.. still scratching my head over that one.

Enabling delayed expansion did the trick, the output is becoming what I want it to be now. Unfortunately, the repetition of the pattern throughout the files has provided me with 11 places in which the pattern repeats, and I'm searching for 1...

Which brings me to my next problem. Right now, I have 10 "FOR" loops (three of them nested), 11 files being created and the file I'm searching through is a slim 45KB instead of the 10,000KB that it could get up to. And, I'm only searching for a pattern which is 4 lines of text. If I need to expand that into 8 or more, that's going to start consuming time. Is there any way to manipulate the flow of data so that it works more efficiently?

As for output, what I'm looking for is a single instance of a known pattern within the file, which comes immediately before the data I'm searching for. In order to find its location, I grabbed the line numbers from each text I was searching for, and output them, then compared them. My comparison of the 4 files (one for each string in the pattern) has yielded 11 locations where the 4-string pattern is found. I need to find a pattern which yields 1 single location. Once I can find that, I'm sure I can figure out the rest on my own. Don't want to make it too easy on myself. :P

gh0std0g74:
to a newbie, its good effort. to a non newbie, the code is so inefficient. 10 nested for loops??? there is definitely more better ways to do what you want, just that i can't understand what you are writing. that's why i ask you to show your final output!!  best if you can show samples of you input files also, because they are apples and oranges, and nowhere did i see {ACAD_REACTORS or 330.....

Dias de verano:
Query...

Source file...


--- Code: ---Some lines
Of text
That are irrelevant (?)
line containing (or consisting of?) {ACAD_REACTORS
line containing (or consisting of?) 330           
line containing (or consisting of?) C             
line containing (or consisting of?) 102           
The Data
You are
Looking for
(How many lines?)
--- End code ---

Dias de verano:

--- Quote from: gh0std0g74 on May 03, 2009, 02:25:14 AM ---to a newbie, its good effort. to a non newbie, the code is so inefficient. 10 nested for loops??? there is definitely more better ways to do what you want, just that i can't understand what you are writing. that's why i ask you to show your final output!!

--- End quote ---

The multiple temp files are inefficient too

gh0std0g74:

--- Quote from: Dias de verano on May 03, 2009, 02:29:41 AM ---The multiple temp files are inefficient too


--- End quote ---
true

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version