could we perhaps see the file test.txt?
PS I like that "REM remove all text after end". That's like "REM relational database goes here"... A good start... Shows you're making an effort...
Do you mean you want to do this?
Before:-
apples
pears
bananas
end
mangos
lemons
After:-
apples
pears
bananas
end
What confuses me, is that the obvious, the blindingly obvious way to do this is to load the file into a text editor such as Notepad, highlight the text you don't want, and press "delete". I am wondering if you need to do this for homework, or possibly just because you fancy learning how to do batch programming. I'll be charitable and assume the latter, but in either case it would be unhelpful of anyone to just go ahead and write a batch file for you. You would not learn anything that way.
If you like batch programming, and you find it interesting, and you are a curious sort of person, you can hunt around just on this forum and find the answers that you need. If none of those things are true, why are you bothering?
What I am willing to do is sketch out the steps you need (in my opinion) to follow.
1. examine the first line in the file.
2. If it's not the "end" line, write the line out to another file.
3. If it is the "end" line, write the line out and jump out of the loop. (hint: to a label)
4. If it wasn't the end line, get the next line.
5. Keep going until you either find the "end" line or the end of the file.
Maybe you could start by writing a batch that just echoes each line of a file, and only then think about doing some decision making?