Grab variable wihin a line of text that contains constants..
Posted: 21 Feb 2013 22:35
I would like to use as the variable for my code below, instead of what came after ClassName=in 1.txt, I would like what came in-between this:
EntryText=Ship sunk!|Grid AO 77| Grab variable HERE, (notice the comma at the end)
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 a word or a different two pair of letters and numbers, or any mixture of letters and numbers up until the |
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 know it has something to do with this, but I don't know how to apply it to the code above
EntryText=Ship sunk!|Grid AO 77| Grab variable HERE, (notice the comma at the end)
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 a word or a different two pair of letters and numbers, or any mixture of letters and numbers up until the |
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.
Code: Select all
@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 know it has something to do with this, but I don't know how to apply it to the code above
Code: Select all
for /f "tokens=3 delims=|" %%C in ("%%B") do for /f "tokens=1 delims=," %%D in ("%%C") do echo %%D