1.

Solve : For Loops and Strings in DOS Batch Files?

Answer»

I am in need of a batch FILE to do the following:

for %%cust in (abcde fghij klmno pqrst uvwxy) do command %%cust,XX,YY,%%substringofcust

In order words, the 'command' should be:

command abcde,XX,YY,abc
command fghij,XX,YY,fgh
command klmno,XX,YY,klm

etc..........

I can't figure out how to PULL only a portion of the customerI think your description of the the task requirements is just a tad too opaque.
Set up your list in a file. Ex:

<>
abcde
fghij
klmno
pqrst
uvwxy

Then use the following batch:

Code: [Select]echo off
setlocal enabledelayedexpansion

for /f "delims=" %%A in (List.txt) do (
  set sub=%%A
  set sub=!sub:~0,3!
  command %%A,XX,YY,!sub!
)

The way to grab the substring is in the second line. What it is saying is SET the SUB VARIABLE to the SUB variable offset by 0 characters for 3 characters. Essentially, take the first 3 characters of the sub variable (which was previously set to be the customer string) and make them the new sub variable. This only works if you know that you are always GOING to use the characters at specific positions within the string. If what you are looking for varies in it's location, it will take some different coding to get it. Please let us know if this is the case.



Discussion

No Comment Found