Hi,
Can we use string as a delimiter ? ( Please see below. "one" is string delimiter )
for /F "tokens=1,2 delims=~" %%a in ("CheckoneThat") do
(
echo %%a>>Out.txt
echo %%b>>Out.txt
)
Expected Results:
Check
That
-Thanks
Batch Script - Using String as a delimter.
Moderator: DosItHelp
Re: Batch Script - Using String as a delimter.
You only can work around it e.g. using string manipulation. Choose a character that most likely won't occur in your strings. Replace "one" with this character and use it as delimiter.
Steffen
Code: Select all
set "str=CheckoneThat"
for /f "tokens=1,2 delims=~" %%a in ("%str:one=~%") do (
>>"Out.txt" echo %%a
>>"Out.txt" echo %%b
)
Steffen
Re: Batch Script - Using String as a delimter.
Very cool. That works. Thank you !
aGerman wrote:You only can work around it e.g. using string manipulation. Choose a character that most likely won't occur in your strings. Replace "one" with this character and use it as delimiter.Code: Select all
set "str=CheckoneThat"
for /f "tokens=1,2 delims=~" %%a in ("%str:one=~%") do (
>>"Out.txt" echo %%a
>>"Out.txt" echo %%b
)
Steffen
Re: Batch Script - Using String as a delimter.
Hi There,
Let us say a input file with the following contents.
File Name : Input.txt
Input.txt file content: asd:asdfa:sdfwe:Firstonesecondonethirdonefourth
Expected results:
Out.txt:
sdfwe
Out2.txt:
First
Third
somehow, below is not working. am i missing something ?
@echo off
setlocal
for /f "tokens=3* delims=:" %%a in (Input.txt) do (
setlocal EnableDelayedExpansion
set string1=%%a
set string2=%%b
echo !string1!>>Out.txt
for /f "tokens=1,3 delims=~" %%c in ("%string2:one\=~%") do (
setlocal EnableDelayedExpansion
echo %%c>>Out2.txt
echo %%d>>Out2.txt
)
)
Thanks !
Let us say a input file with the following contents.
File Name : Input.txt
Input.txt file content: asd:asdfa:sdfwe:Firstonesecondonethirdonefourth
Expected results:
Out.txt:
sdfwe
Out2.txt:
First
Third
somehow, below is not working. am i missing something ?
@echo off
setlocal
for /f "tokens=3* delims=:" %%a in (Input.txt) do (
setlocal EnableDelayedExpansion
set string1=%%a
set string2=%%b
echo !string1!>>Out.txt
for /f "tokens=1,3 delims=~" %%c in ("%string2:one\=~%") do (
setlocal EnableDelayedExpansion
echo %%c>>Out2.txt
echo %%d>>Out2.txt
)
)
Thanks !
Re: Batch Script - Using String as a delimter.
There are two main reasons.
1) You didn't use exclamation marks for variable string2.
2) You try to replace one\ but there is no backslash in your string.
Steffen
1) You didn't use exclamation marks for variable string2.
2) You try to replace one\ but there is no backslash in your string.
Code: Select all
@echo off
setlocal
for /f "usebackq tokens=3* delims=:" %%a in ("Input.txt") do (
set string1=%%a
set string2=%%b
setlocal EnableDelayedExpansion
>>"Out.txt" echo !string1!
for /f "tokens=1,3 delims=~" %%c in ("!string2:one=~!") do (
endlocal
>>"Out2.txt" echo %%c
>>"Out2.txt" echo %%d
)
)
Steffen
Re: Batch Script - Using String as a delimter.
Nice.. Thank You. It did work without adding the backslash.
Will there be any input file size limit when using for loop?
It would be great if you can share any previous posts are available on this topic.
Thanks !!
Will there be any input file size limit when using for loop?
It would be great if you can share any previous posts are available on this topic.
Thanks !!
Re: Batch Script - Using String as a delimter.
mendax_r wrote:Will there be any input file size limit when using for loop?
No the file size is not limited. Although a FOR /F loop buffers the data. That means it will most likely take quite a while before it even begins to iterate.
The only real limit in this context is the string lenth that is, 8191 characters.
mendax_r wrote:It would be great if you can share any previous posts are available on this topic.
Not sure what you mean. There are more than 6500 Threads at DosTips. I don't remember them all. If you want to search for a specific DosTips topic then use
your search term site:dostips.com
at Google. At least I wouldn't do anything else to find related topics for you.
Steffen
Re: Batch Script - Using String as a delimter.
Cool. Thank You..