Solved

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

Posted on 2013-11-08
6
488 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Do email signature updates give you a headache?

Do you feel like you are constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

Join & Write a Comment

Suggested Solutions

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now