I am trying to remove the first word from a string in batch.
Example: "this kid loves batch" to "kid loves batch"
I have tried:
@echo off
set /p text=text:
for /f "tokens=1,*" %%a in ("%text%") do set updated=%%a
echo %updated%
pause
It just outputs the first word, and does not delete the first word.
How can I make it delete the first word, and keep the rest of the string?
You can do it without the for loop too:
@Echo Off
Set/P "text=text: "
Set "updated=%text:* =%"
Echo(%updated%
Timeout -1
When you use "tokens=1,*" with the default delimiter in a for loop where the variable is %%a, everything to the left of the first whitespace character is stored in %%a, while everything else is stored in %%b.
To get everything after the first word, simply change set updated=%%a to set updated=%%b
@echo off
set /p text=text:
for /f "tokens=1,*" %%a in ("%text%") do set updated=%%b
echo %updated%
pause
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With