help needed with interpreting strings and acting in response
Moderator: DosItHelp
help needed with interpreting strings and acting in response
I am stumped at this how to do this. I have literally tried for about 5 weeks, every day to get this to work and it hasn't. So don't say that i am pestering the forum.
Now, to business:
I need a batch file that finds a text string from a text file (both are internally specified, not user specified) and does something if it is found. If it is not found, the batch file jumps to the next point in the batch file. But it must also set the text next to it on the line as a variable (a standard %(something)% variable).
Could you please post how to do this? I know it sounds confusing, but could you please try and understand it, I really need help!
Thanks in advance,
Rileyh
EDIT- In response to your posts I have modified the title.
EDIT2- In response to your posts I have modified the content.
Now, to business:
I need a batch file that finds a text string from a text file (both are internally specified, not user specified) and does something if it is found. If it is not found, the batch file jumps to the next point in the batch file. But it must also set the text next to it on the line as a variable (a standard %(something)% variable).
Could you please post how to do this? I know it sounds confusing, but could you please try and understand it, I really need help!
Thanks in advance,
Rileyh
EDIT- In response to your posts I have modified the title.
EDIT2- In response to your posts I have modified the content.
Last edited by Rileyh on 21 Nov 2011 00:24, edited 1 time in total.
Re: PLEASE HELP ME!
You need to provide more specific info, such as:
what are you searching? - a file? text in a variable? directory file names?
what type of search(es) are you trying to do? - regular expression? simple string match?
what have you tried that failed?, hopefully distilled down to the essentials of the problem without extraneous details
Dave Benham
what are you searching? - a file? text in a variable? directory file names?
what type of search(es) are you trying to do? - regular expression? simple string match?
what have you tried that failed?, hopefully distilled down to the essentials of the problem without extraneous details
Dave Benham
Re: PLEASE HELP ME!
dbenham wrote:You need to provide more specific info, such as:
what are you searching? - a file? text in a variable? directory file names?
what type of search(es) are you trying to do? - regular expression? simple string match?
what have you tried that failed?, hopefully distilled down to the essentials of the problem without extraneous details
Dave Benham
Yes, and please refrain from using such despicable titles.
Re: help needed with interpreting strings and acting in resp
Rileyh wrote:I need a batch file that finds a text string from a text file (both are internally specified, not user specified) and does something if it is found. If it is not found, the batch file jumps to the next point in the batch file. But it must also set the text next to it on the line as a variable (a standard %(something)% variable).
OK, I tried to understand but I didn't. An example could be helpful.
Imagin you have a file called "test.txt" with the following content:
Code: Select all
AAA WWW
BBB XXX
CCC YYY
DDD ZZZ
Say you are looking for string BBB. What will happen if it is found and what if it's not found? Try to explain with the given example or write your own that would suit you according to your requirement.
Regards
aGerman
Re: help needed with interpreting strings and acting in resp
In the text file:
So pretend I am looking for the string BBB. I want my code to look for that string and check if it is there. And it is, so it will be set to echo whatever comes after it on the line, in this case it will echo xxx. And it also makes the variable %a% be set to xxx (the next thing on the line).
So in another scenario there is this in the txt file:
My code will find "printline" and set %(any variable name that i come up with)% to the next thing on the line. And when it finds "printline", it is set to do "echo" in its place. See what I mean?
Sorry about the poor explanation that I gave before.
Regards,
Rileyh
Code: Select all
AAA WWW
BBB XXX
CCC YYY
DDD ZZZ
So pretend I am looking for the string BBB. I want my code to look for that string and check if it is there. And it is, so it will be set to echo whatever comes after it on the line, in this case it will echo xxx. And it also makes the variable %a% be set to xxx (the next thing on the line).
So in another scenario there is this in the txt file:
Code: Select all
printline xxx
My code will find "printline" and set %(any variable name that i come up with)% to the next thing on the line. And when it finds "printline", it is set to do "echo" in its place. See what I mean?
Sorry about the poor explanation that I gave before.
Regards,
Rileyh
Re: help needed with interpreting strings and acting in resp
'
Specific question, specific answer.
untested !
Specific question, specific answer.
Code: Select all
@echo off &setlocal enableDelayedExpansion
set "$file=input.TXT"
set "$match=BBB"
for /f "usebackq tokens=*" %%? in (
"!$file!"
) do (
set "$$=%%~?"
set "$$=!$$:%$match%=!"
if /i ["!$$!"] neq ["%%~?"] (
echo.$$=!$$!_
)
)
Re: help needed with interpreting strings and acting in resp
How can I implement this code in my program?
It does not have the next characters on the line as a standard %(something)% variable.
Could you show me how to do that?
Regards,
Rileyh
PS- I am only asking this question because the syntax is unlike anything I have seen before and therefore I cannot modify it safely.
Sorry if this inconveniences you.
It does not have the next characters on the line as a standard %(something)% variable.
Could you show me how to do that?
Regards,
Rileyh
PS- I am only asking this question because the syntax is unlike anything I have seen before and therefore I cannot modify it safely.
Sorry if this inconveniences you.
Re: help needed with interpreting strings and acting in resp
'
Not sure I understand your question, you can access variable $$ as !$$!, The %$$% isn't like that in for loops !Rileyh wrote:It does not have the next characters on the line as a standard %(something)%
Re: help needed with interpreting strings and acting in resp
Could you also show me where the "function" section is? (the part where I define what to do when it finds the "BBB" string?
Sorry for continued pestering, Ed, but I really need it,
Regards,
Rileyh
Sorry for continued pestering, Ed, but I really need it,
Regards,
Rileyh
Re: help needed with interpreting strings and acting in resp
'
Code: Select all
@echo off &setlocal enableDelayedExpansion
set "$file=input.TXT"
set "$match=BBB"
for /f "usebackq tokens=*" %%? in (
"!$file!"
) do set "$$=%%~?" &set "$$=!$$:%$match%=!" &if /i ["!$$!"] neq ["%%~?"] (
::
echo. '!$match!' appears in line:
echo. '%%~?'
echo. $$=!$$!_
echo. the part where I define what to do when it finds the "BBB" string
)
Re: help needed with interpreting strings and acting in resp
Code: Select all
echo. the part where I define what to do when it finds the "BBB" string
)
Does that mean that that is the part where I write what happens, or does it mean that that is the part where the defining ends?
In other words, is that the point at which I can write code to define what happens, or is that where the defining ends and before that is where I define what happens?
By the way, sorry about asking about the %(something)% bit. I don't know why I didn't see the !$$! variable
Thanks again,
Rileyh
Re: help needed with interpreting strings and acting in resp
'
that is the point at which you can write code to define what happens.
What actually is it you want to do when you find a match
that is the point at which you can write code to define what happens.
What actually is it you want to do when you find a match
Re: help needed with interpreting strings and acting in resp
This will be used to make a batch compiler. The string "BBB" is just a pretend string. Really it will be a batch command. The user will type code into an environment and then save it as a batch file. But they have the option to press F5 to run it and that will run a batch file (which contains the code that I need, that is what I am asking how to write) that finds a command and if it works do what that command does. Hence the section on "what to do when found", I need to use that section to define what to do when it finds "echo" for example.
Regards,
Rileyh
Regards,
Rileyh
Re: help needed with interpreting strings and acting in resp
I have tested it and Ed Dyreen, you are a genius!!!!!!!!!!
How the hell do you make this stuff?
You have no idea how grateful I am!
But one last question: I have inserted this code:
But when I run this, pauses, even when there is no "pause >nul" in the file "test.txt". H
How do I get it to pause only if the string is found, and not just do it anyway?
But thank you so much again,
Rileyh
How the hell do you make this stuff?
You have no idea how grateful I am!
But one last question: I have inserted this code:
Code: Select all
set "$file=test.txt"
set "$match=pause >nul "
for /f "usebackq tokens=*" %%# in (
"!$file!"
) do set "$$=%%~#" &set "$$=!$$:%$match%=!" &if /i ["!$$!"] neq ["%%~#"] (
::
pause >nul
)
But when I run this, pauses, even when there is no "pause >nul" in the file "test.txt". H
How do I get it to pause only if the string is found, and not just do it anyway?
But thank you so much again,
Rileyh
Re: help needed with interpreting strings and acting in resp
unfortunately it didn't work, Ed.
Could you try again?
Regards,
Rileyh
Could you try again?
Regards,
Rileyh