[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2013-11-08
6
Medium Priority
?
498 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
[X]
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
  • 3
  • 2
6 Comments
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 300 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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
LVL 43

Accepted Solution

by:
Steve Knight earned 1700 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

649 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