FOR woith two variables?

Microsoft Windows 7 home premium
August 4, 2010 at 14:42:59
Specs: Windows 7
Echo Changing ownership of groups from textfile
echo --------------------------------
set filename=
set name1=
set name2=
@set /P filename=Please enter filename of group list: %=%
@set /P name1=Please enter name of owner to replace: %=%
@set /P name2=Please enter new owner name: %=%
echo Processing...
FOR /F "delims=~" %%f in (%filename%) DO dsquery group -samid "%%f" | dsget group -desc>>temp1.txt
sed "s/%name1%/%name2%/g" temp1.txt>>temp2.txt
sed "/desc/d" temp2.txt>>temp3.txt
sed "/dsget succeeded/d" temp3.txt>>newownership.txt

What this program have to do is changing all names at description of group at AD....The list of groups is given in text file of your choice (filename variable)...the string to replace is in name1 var...name2 is new name.
I have found "sed" command for batch creates succesfully newownership.txt with modified descriptions of all groups (string name1 is repleced by name2 string).
And now starts the tricky part...
I need to make For loop and dunno how, because it should use two variables.I will explain what I want to achieve.
FOR /F "delims=~" %%f in (%filename%) AND %%g in (newownership.txt) DO dsquery group -samid "%%f" |dsmod group -desc "%%g"
So I need a loop to take line by line from one txt file into variable (for example %%f) and also to take line by line from newownership.txt file as a variable, and to put both into syntax which will change old description of (%%f) group to the new group description (%%g).
Is it possible to do that in DOS?

See More: FOR woith two variables?

Report •

August 5, 2010 at 07:37:49
You probably want something like this:

@echo off

setlocal EnableDelayedExpansion

set n=0
set skp=
for /f "delims=" %%a in (File1.txt) do (
  set /a n+=1
  call :GetNextLine
  echo %%a !line!
  set skp=skip=!n!
goto :eof

for /f "%skp% delims=" %%a in (File2.txt) do (set line=%%a & goto :eof)

Report •
Related Solutions

Ask Question