0

I'm trying to get my batch script to work and I'm running into an issue. The two lines I provided are where the issue is. What I'm doing is pulling information from two different text files, but I'm not sure how to code it to pull from both files on line 2 in their respective positions. So I need to pull %%n from name.txt and %%s from server.txt

 FOR /F %%n IN (name.txt) DO PACLI STOREPASSWORDOBJECT SAFE="PACLI Test" FILE="%%n" PASSWORD="1234567890"
 FOR /F %%s IN (server.txt) DO PACLI ADDFILECATEGORY SAFE="PACLI Test" FILE="%%n" CATEGORY="Address" VALUE="%%s"

Any help would be greatly appreciated, because I'm not a very good programmer.

Thanks

The Text files would look like this:

Name.txt:

  • Unix_Test_Server_Root_01
  • Unix_Test_Server_Root_02

Server.txt:

  • SDCServerABC01
  • SDCServerABC02
Tom
  • 1
  • 2
  • 2
    `%%n` in your second line is out of scope of the first `for /F` loop, so the solution could perhaps be to nest the second `for /F` loop into the first one; but without knowing how the text files look and how many lines are to be read, it is hard to tell... – aschipfl Oct 03 '16 at 11:24
  • So are you saying there is a one to one relationship between both text files? Would help us help you to post an example of each of the text files. – Squashman Oct 03 '16 at 13:18
  • See [combinining-multiple-text-files-into-one](http://stackoverflow.com/questions/14521799/combinining-multiple-text-files-into-one), or [extracting-all-lines-from-multiples-files](http://stackoverflow.com/questions/32738831/extracting-all-lines-from-multiples-files), or [define-a-new-handle-similar-to-stdout](http://stackoverflow.com/questions/19920517/define-a-new-handle-similar-to-stdout), or ... – Aacini Oct 03 '16 at 13:33
  • Thanks guys! So each text files will have one or more lines. FOr example, the name.txt would look like this: Unix_Test_Server_Root_01 Unix_Test_Server_Root_02 etc... The Server.txt would look like this: SDCServerABC01 SDCServerABC02 etc... – Tom Oct 04 '16 at 11:47
  • I need to read the name.txt file from the top on line 2 after it's read on line one. If that makes sense? – Tom Oct 04 '16 at 11:51

1 Answers1

0

use a trick to read both files simultaniously:

@echo off
setlocal enabledelayedexpansion 

<server.txt (
  for /f %%a in (name.txt) do (
    set /p server=
    echo Server !server!, Name %%a
  )
)

Output:

Server SDCServerABC01, Name Unix_Test_Server_Root_01
Server SDCServerABC02, Name Unix_Test_Server_Root_02
Stephan
  • 53,940
  • 10
  • 58
  • 91