0

I would like to use as the variable for my code below, instead of what comes after ClassName= in 1.txt, I would like what comes in-between this:

EntryText=Ship sunk!|Grid AO 77|Variable,

(notice the comma after the variable and the | before it )

So grab after the text line ending with the second | and before the comma.

The text line before the variable will be the same and constant EXCEPT after "Grid" there could be any mixture of letters and numbers up until the second |

So I am trying to use as a variable, what is in between:

EntryText=Ship sunk!|Grid (Any combination of letters or numbers) | (variable) , (comma)

So grab in between the second | and the comma. Than you. I would like to replace the grabbing of the variable after ClassName= to what is in between the second | and the comma. Please keep in mind that there are other | and commas in the file that I don't want to grab, I just want to grab the variable after | and before comma if its after the "EntryText=Ship sunk!|Grid ....

Again, I don't want the Grid part, I'd like what comes after the second | and before the comma. There will be many EntryText lines as well, so I'd like to grab that part of all of them and put in my code.

So instead of what is after ClassName=, I'd like to copy what is where the variable listed above.

Thank you for your time!!

@echo off

copy 2.txt 2.txt-backup

setlocal enableDelayedExpansion

>2.txt (
for /f "tokens=1* delims=:" %%A in ('findstr /n "^" 2.txt-backup') do (
( echo !ln!| findstr "^Type=206$" >NUL && set ln=ln ) || (
    set "ln=%%B"
    if "!ln:~0,6!"=="Class=" (
        findstr /c:"ClassName=!ln:~6!" "E:\Dropbox\New folder\Log_*.txt" >"E:\Dropbox\New folder\null" && (
            echo Class=ShipDummy
            set "ln=Type=206"
        )
    )
    if #!ln!==# (echo;) else echo !ln!
)
)
)

I was given this bottom code by someone, but I don't know if its what I want or how to apply it to the above:

for /f "tokens=3 delims=|" %%C in ("%%B") do for /f "tokens=1 delims=," %%D in ("%%C") do echo %%D

Thank you!!!!!

machiavelli
  • 92
  • 1
  • 1
  • 9
  • It's not clear what you're looking for. Once you scrape **variable**, what do you want to do with it? Do you want to echo it out to 2.txt instead of the `Class=ShipDummy` thing? Do you want to echo it out to `E:\Dropbox\New Folder\null`? – rojo Feb 22 '13 at 12:51
  • I'd like to do what it already does in 2.txt. So it would match what is after Class= in 2.txt and then replace that with Class=ShipDummy. Thank you. – machiavelli Feb 22 '13 at 20:21
  • @machiavelli: with 11 questions asked and only 2 up votes doubtful you'll receive much help. – orangepips Feb 25 '13 at 14:26

1 Answers1

1

I think you want something like this...

...
set "ln=%%B"
for /f "tokens=3 delims=|" %%C in ("%%B") do for /f "tokens=1 delims=," %%D in ("%%C") do set "MyVar=%%D"
findstr /c:"ClassName=!MyVar!" "E:\Dropbox\New folder\Log_*.txt" >"E:\Dropbox\New folder\null" && (
    echo Class=ShipDummy
    ...
David Ruhmann
  • 11,064
  • 4
  • 37
  • 47
  • I tried your code and its turning everything into Class=ShipDummy then Type=206, then ln on the third line. Thank you for your effort. – machiavelli Feb 22 '13 at 20:42
  • I'd just like what is in between the second | and the , to be replaced in 2.txt with Class=ShipDummy, also below that keeping the Type=206 – machiavelli Feb 22 '13 at 20:43
  • the second | and the comma – machiavelli Feb 22 '13 at 20:55
  • I did think of a simpler way to do what I want to achieve, please see here: http://stackoverflow.com/questions/15033351/search-for-a-list-of-words-on-a-file-then-find-those-words-on-another-replacing – machiavelli Feb 22 '13 at 21:26