For example, I have a line
2054721111*2054721111*2054721111*2054721111
Now, I want to replace "*" character as a new line.
What if I want my output to be like this using batch file?
2054721111*
2054721111*
2054721111*
2054721111
For example, I have a line
2054721111*2054721111*2054721111*2054721111
Now, I want to replace "*" character as a new line.
What if I want my output to be like this using batch file?
2054721111*
2054721111*
2054721111*
2054721111
@echo off
setlocal
set "data=2054721111*2054721111*2054721111*2054721111"
Rem Option 1 - first count how many elements there are in the string
Rem and then loop over them
setlocal enableextensions disabledelayedexpansion
for /f %%n in (
'cmd /q /u /c "echo(%data%"^|find /c "*"'
) do for /l %%i in (0 1 %%n) do (
setlocal enabledelayedexpansion
for /f "tokens=1,* delims=*" %%a in ("!data!") do (
endlocal
set "data=%%b"
if defined data (echo(%%a*) else (echo(%%a)
)
)
endlocal
Rem Option 2 - without counting the number of elements
setlocal enableextensions disabledelayedexpansion
cmd /q /v:on /e:on /c "for /l %%l in () do if not defined data (exit) else for /f "tokens=1,* delims=*" %%a in ("!data!") do (set "data=%%b" & if defined data (echo %%a*) else echo %%a)"
endlocal
Both codes show the same idea: use *
as a delimiter in a for /f
loop, output the first token and save the rest of the line as the input variable. Keep processing until all the tokens has been echoed.
First block of code will not have any problem with exclamations in the data (in the case they could exist), but the second one can fail
With Notepad++, just do that:
Ctrl-F, Select Replace tag then:
Find what: \*
Replace with: \n
Clic on Replace all
.