the literal answer to your question would be "by using Notepad and your keyboard"
The answer, you want to read:
use substring replacement to remove everything from the start until (including) your search word. (see set /?
)
Use a for
loop to get the first word from the rest of the string. (see for /?
)
@echo off
echo my name is xyz. i like science. i like to play volleyball and drink whiskey. >abc.txt
<abc.txt set /p "text="
for /f "delims=.,;! " %%a in ('echo %text:* play =%') do set result=%%a
echo the found word is: %result%
REM to write the found word into a new file, use redirection:
echo %result% >xyz.txt
Edit to match what needs to do with multiple lines ?
:
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%z in (abc.txt) do (
set "text=%%z"
for /f "delims=.,;! " %%a in ('echo "!text:* play =!"') do set "result=%%~a"
echo !result! >>xyz.txt
)
Some small changes needed; delayed expansion, another for /f loop
wraped around and appending to file with >>
.
Note: Please don't make this a endless changing question. When you have another problem, please ask a new question