Question: For example I have a text file `test.txt` that contains like this:

> 
> 
> ```
> Item1 $23 Item2 $24
> Item3 $25
> 
> ```
> 
> 

When I run this script:

```
@echo off
for /f "delims=$ tokens=1*" %%A in (test.txt) do echo %%B >> result.txt

```

The result is:

> 
> 
> ```
> 23 Item2 $24
> 25
> 
> ```
> 
> 

I want the result is:

> 
> 
> ```
> 23
> 24
> 25
> 
> ```
> 
> 

How should I repair the script?

Answer: 
Try the following script (see the explanatory `rem` remarks in the code):

```cmd
@echo off
setlocal EnableExtensions DisableDelayedExpansion

rem // Define constants here:
set "_IFILE=test.txt"
set "_OFILE=result.txt"

rem // Store line-break in variable:
(set ^"LF=^
%= blank line =%
^")

rem // Write to resulting file:
> "%_OFILE%" (
    rem // Loop through lines of text file:
    for /F "usebackq delims=" %%L in ("%_IFILE%") do (
        rem // Store current line in variable:
        set "LINE=%%L"
        rem // Toggle delayed expansion to be able to write and read variable in same code block:
        setlocal EnableDelayedExpansion
        rem // Replace each `$` by line-break and loop over resulting lines skipping the first one:
        for /F "skip=1" %%K in (^"!LINE:$^=^%LF%%LF%!^") do (
            rem // Return first token of each line:
            echo(%%K
        )
        endlocal
    )
)

endlocal
exit /B

```

At first, this replaces every `$` by a line-break, so the first line of `test.txt` becomes:

> 
> 
> ```cmd
> Item1 
> 23 Item2 
> 24
> 
> ```
> 
> 

And the second one becomes:

> 
> 
> ```cmd
> Item3
> 25
> 
> ```
> 
> 

Then it extracts the first `SPACE`- or `TAB`-separated token from each of the newly formed multi-line strings, skipping the first line, so only the numbers are returned.
I have decided to post this example [batch-file](/questions/tagged/batch-file "show questions tagged 'batch-file'") to show a method of parsing each line and returning every other string, *(doesn't work with poison characters)*.

```bat
@(For /F "UseBackQDelims=" %%A In ("test.txt")Do @(Set "i=0"
    For %%B In (%%A)Do @(Set /A "i=(i+1)%%2"&Cmd /V:On /Q /C Exit !i!
        If Not ErrorLevel 1 Echo %%B)))>"results.txt" 

```

In your posted example code and 'wanted' result, you could probably use that idea to output the strings with their first character removed if it is a `$`.

```bat
@(For /F "UseBackQDelims=" %%A In ("test.txt")Do @(Set "i=0"
    For %%B In (%%A)Do @(Set /A "i=(i+1)%%2"&SetLocal EnableDelayedExpansion
        If !i! Equ 0 (Set "Val=%%B"&If "!Val:~,1!"=="$" (Echo !Val:~1!
            )Else Echo %%B)&EndLocal)))>"results.txt"

```