Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract text after $ in batch file?

Tags:

batch-file

I have a batch file that would have something like this:

50-A Description of the item $23

I have a script that extracts whatever is before the $ sign, but I need to extract everything after the $ sign.

Here's the script:

for /f "tokens=1 delims=/" %%a in (test.txt) do (echo %%a >> newfile.txt)

How would I change it?

like image 539
Mark Deven Avatar asked Dec 13 '22 19:12

Mark Deven


1 Answers

No matter how many $ you have in the line, you can easily get the text after the last one like so:

set "str=Te$ting thi$ $cript for $zero"
set "result=%str:$=" & set "result=%"
echo %result%

Your result in this case would be zero.

like image 193
Timtech Avatar answered Dec 18 '22 00:12

Timtech