Dear Orange/agerman,
i have a doubt is it possible to separate a string in substring in DOS(input file are in .txt format),example
input:-
2323,344429890
41234,454324424252
41241,35433353535
output:-
have to print only first 4 number in second column
3444
4543
3543
Thanks in advance
Substring
Moderator: DosItHelp
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: Substring
Oh, being singled out? That's a first.
If you want to store these numbers all in variables it would be different, but to do exactly as you said is also very easy.
Without delayed expansion:
With delayed expansion:
delims=,
2323,344429890
tokens=2
2323,344429890
tempvar:~,4 (same as tempvar:~0,4)
2323,344429890
If you want to store these numbers all in variables it would be different, but to do exactly as you said is also very easy.
Without delayed expansion:
Code: Select all
for /f "delims=, tokens=2" %%a in (input.txt) do (
set tempvar=%%a
call echo:%%tempvar:~,4%%
)
With delayed expansion:
Code: Select all
setlocal enabledelayedexpansion
for /f "delims=, tokens=2" %%a in (input.txt) do (
set tempvar=%%a
set tempvar=!tempvar:~,4!
echo:!tempvar!
)
delims=,
2323,344429890
tokens=2
2323,344429890
tempvar:~,4 (same as tempvar:~0,4)
2323,344429890