0

I have this list in batch:

set list=12,34,56
echo %list%

How can I get the list to print only 34?

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
schenker
  • 941
  • 3
  • 12
  • 25
  • What operating system are you using? – Ross Ridge Nov 27 '20 at 03:26
  • Im using windows 10 Pro – schenker Nov 27 '20 at 03:29
  • See my answer [here](https://stackoverflow.com/a/64762748/12343998) for a means of access elements of a list by index. – T3RR0R Nov 27 '20 at 03:34
  • 1
    @aschipfl With all due respect, the question linked as duplicate is like recommending a sledgehammer to kill a fly ;-) [How to loop through comma separated string in batch?](https://stackoverflow.com/questions/17158719/how-to-loop-through-comma-separated-string-in-batch) may be a closer match. – dxiv Nov 28 '20 at 06:47
  • I see, @dxiv, you're right; once I'm at a computer I'll add the link you're suggested (it can't be done via mobile)… – aschipfl Nov 28 '20 at 12:45

1 Answers1

2

To print the second number 34:

for /f "tokens=2 delims=," %%a in ("%list%") do @echo %%a

To print all 3 numbers 12 34 56:

for /f "tokens=1-3 delims=," %%a in ("%list%") do @echo %%a %%b %%c

The double percents in %%a are required in a batch file. At the command prompt, use just %a.

dxiv
  • 16,984
  • 2
  • 27
  • 49