Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Help trying to pull variables from a tab delimited text file into a script.

Posted on 2013-11-08
6
492 Views
Last Modified: 2013-11-09
Hello, I am trying to pull 2 variables from a tab delimited text file to run a batch script.

I have one batch script which calls the other and the data from the text file.

For /F %%x %%y n (feed.txt) do import.bat %%x %%y

Then I input %1 for variable1 and %2 for variable2
When I run the import.bat file as follows "import.bat username card#" it works.

My text file is tab delimited.

variable1  variable2

Ideally I would like to have a text file user variable1 ignore variable2 and use variable3 but I can run another export with jsut the 2 variables. Thanks in advance.
0
Comment
Question by:njtreker
  • 3
  • 2
6 Comments
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 75 total points
ID: 39634978
If I understand you correctly, this should work:
For /F "tokens=1,3" %%x in (feed.txt) do import.bat %%x %%z

Open in new window

That should bring in variable 1 & 3, skipping variable 2...if not, then we need to know what the delimeter is...by default it's a space character.  But if your text file is broken up like:

data1,data2,data3

Then you could use:
For /F "tokens=1,3 delims=," %%x in (feed.txt) do import.bat %%x %%z

Open in new window


If that doesn't sort it - can you post an example of the file?
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39635007
Agreed with sirbounty there, the default delims should work with tab OK, though I think if you are choosing the tokens you want:

For /F "tokens=1,3" %%x in (feed.txt) do call import.bat %%x %%y

Open in new window


or:

For /F %%x in (feed.txt) do call import.bat %%x %%z

Open in new window


The CALL to run the other batch file for each line in the text file and x/y if specifiying token 1&3, or x/z if not.

Also your other import.bat file, is it worth us incorporating the loop into that instead?

Steve
0
 

Author Comment

by:njtreker
ID: 39635645
I am a lot closer. Thanks! I can't get the batch file to read variable 3. When I run it it interprets it as %%z. If I change may launch file, change the variable number to 2 and the %%z to %%y, and remove variable 2 and just have 2 variables it works. Below are my files. I changed some of the data of course for privacy. Variable 1 is a username, Variable2 is a ID # and Variable3 is a card #. For this process I need username and card #

Files:

Procimportlaunch.bat

@echo off
rem Iterate through each line of the input file
rem For each line, execute the command with the current line content as a parameter

For /F "tokens=1,3" %%x in (feed.txt) do call import.bat %%x %%z

@echo on

Import.bat

c:
cd \Program Files\PaperCut MF\server\bin\win
server-command set-user-property %1 secondary-card-number %2

Feed.txt

fraxxxx      010712345      13123
maxxx      010912345      13123
jonxxxx      010912345      13123
turxxxxx      014123456      12345

Thanks again for your help. Worse case I have a way to do it,  but I would like to know how to skip variables for the future.
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 43

Accepted Solution

by:
Steve Knight earned 425 total points
ID: 39635647
See my comment.  It is not %%z but %%y.

If you use "tokens=1,3" %%x in (...) then  %%x is the first token and %%y is the 3rd.
If you use "tokens=1,2*" %%x then %%x is first, %%y is secondm, %%z is the rest of the line
if you use no "tokens=" bit then %%x if first, %%y second, %%z third.

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39635648
Seeing your import.bat actually just use:

@echo off
cd /d c:\Program Files\PaperCut MF\server\bin\win
for /f "tokens=1,3" %%x in (feed.txt) do (
  echo Working on %%x and %%y
  ECHO server-command set-user-property %%x secondary-card-number %%y
)

Remove the uppercase ECHO command when it looks right, it will just show to the screen for now.

Steve
0
 

Author Comment

by:njtreker
ID: 39635669
Steve, That's got it, I got confused with Sirbounty's post. Thanks so much both of you!
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This article explains how to install and use the NTBackup utility that comes with Windows Server.
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question