1.

Solve : Echo line in next to last line of file?

Answer»

I got an idea last night for a file but they key to it is I need it to echo a line not at the end of the file, but next to last. I can do it that way or i could make it echo say, on line 25 and then move the current line 25 down a line. how do i do either of these?Hey Gamerx, Do you have an example of what you mean?well i didnt want to reveal my idea yet but i guess. I am working on a BATCH AI Interface. What I need it to do is when you ask an unrecognized question it will ask you what you want the response to that question to be, and then it would echo this line inside of a label towards the end:
if %question%=%ASKED% then echo %name%^>%answer%So essentially, you want the batch file to learn 'on the move'sure... if thats what u call it LOL. and also i need to know how to make an IF statement with spaces, if you know how.I'm guessing it is possible but it would be pretty advanced.

I think it can be done with the delete, >> and call commands to constantly create different parts of the batch file...if you UNDERSTAND what I mean...

For example, if you change a setting (or add something), it would delete another batch file and make a new edited on to replace it. Then use the call command to access the batch file.It's a little hard to understand exactly what you want to do. Are you attempting to alter the batch file that is currently running? If so, I don't think that is possible. I think Carbon Dudeoxide is on the right track. But, you do not need to delete the secondary batch file. Simply overwrite it with the redirect > with the first line sent. Then append it with each ADDITIONAL line with >>.

I think you may be able to do what you want by asking you question with set/p in the batch file. Next echo the answer(the variable created with set/p) to a new batch file. Then call the new batch file. When the new batch file is done it will return to the main batch file and finish up. This way the primary batch file is never altered, while the "Answer batch" is created new every time.

The code might look something like this:
Code: [Select].....
line 22
line 23
echo Question: How old are you?
set/p answer=Enter Your Answer Now!
echo @echo off > answer.bat
echo line 2 > > answer.bat
echo %answer% > > answer.bat
echo last line > > answer.bat
call answer.bat
line 25
exit
Is this like those BASIC AI programs that "learned" which we all typed in to our C64s in the 1980s? You know...

Are you thinking of an animal?
Yes
is it a cat?
no
what is it?
a dog
how can i tell a dog from a cat
a dog barks

etc etc



Discussion

No Comment Found