Reputation: 125
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?
Upvotes: 3
Views: 4591
Reputation: 14305
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
Upvotes: 2
Reputation: 38623
You can do it without the for loop too:
@Echo Off
Set/P "text=text: "
Set "updated=%text:* =%"
Echo(%updated%
Timeout -1
Upvotes: 4