Computing.Net > Forums > Programming > Multiple arguments froma txt file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Multiple arguments froma txt file

Reply to Message Icon

Name: ddan
Date: September 7, 2009 at 19:26:56 Pacific
OS: win2K3
Subcategory: Batch
Comment:

Hi

I need to pass arguments from a txt file to a batch file. The txt file will contain multiple lines, each line will have: un & emaill add.

How do I get a batch file to call the arguments and process line by line till end of file?

your help would be much appreciated!!.Thnaks in advance!



Sponsored Link
Ads by Google

Response Number 1
Name: gtaion
Date: September 7, 2009 at 20:03:13 Pacific
Reply:

Change the name of the text.txt to match the name of your text file.

@echo off
for /f "tokens=*" %%a in (text.txt) do %%a


0

Response Number 2
Name: ddan
Date: September 7, 2009 at 21:09:02 Pacific
Reply:

what im trying to do is a basic sharepoint site restore, not sure if your familiar with the stsadm command, but basically the batch file command is as follows:

stsadm -o createsite -url http://my-site.company.com/personal/%1 -ownerlogin domain\%2 -owneremail %3

so basically I have a txt file with %1, %2 & %3 (accross 1 line) in a tab-del txt file, its a list with a couple of hundred entries.

Id like the batch file to run the above command and grab the enries from the txt file as it completes each line.

can you help with this? thanks!


0

Response Number 3
Name: Mechanix2Go
Date: September 7, 2009 at 22:31:25 Pacific
Reply:

@echo off & setLocal EnableDELAYedExpansion

for /f "tokens=1-3 delims= " %%a in (myfile) do (
stsadm -o createsite -url http://my-site.company.com/personal... -ownerlogin domain\%%b -owneremail %%c
)


=====================================
Helping others achieve escape felicity

M2


0

Response Number 4
Name: ddan
Date: September 7, 2009 at 23:34:12 Pacific
Reply:

Hi thanks for your help with this, but that command doesnt seem to work. Not sure if the %%a, %%b etc is causing an issue for the stsadm command.

I have pasted below from the command window
******************************************

E:\MySites>mysites.bat
ECHO is on.

E:\MySites>for /F "tokens=1-3 delims= " %a in (users_tabDel.txt) do (stsadm -o c
reatesite -url http://my-site-stg.company.com/pers... -ownerlogin DOMAIN\%b -
owneremail %c@COMPANY.com )

E:\MySites>(stsadm -o createsite -url http://my-site-stg.company.com/pers... username firstn.lastn -ownerlogin DOMAIN\ -owneremail @company.com )

Command line error.

************************************************
(between the aster's is what was pasted from the command windows)

any ideas? seems when it runs the stsadm command the parameters are translated incorreclty?


0

Response Number 5
Name: Mechanix2Go
Date: September 8, 2009 at 01:09:34 Pacific
Reply:

Use the script I posted but put ECHO before the stsadm. Then run it and paste the output.


=====================================
Helping others achieve escape felicity

M2


0

Related Posts

See More



Response Number 6
Name: Judago
Date: September 8, 2009 at 01:48:13 Pacific
Reply:

This is a Tab delimited file? It looks to me that a space is being used as a delimiter instead of a tab, therefore the whole line is %%a.

If it's the case all that needs to be done is replace the space after "=" in "delims=" with a tab so the line gets split up correctly.

M2's script isn't in pre tags so the tab would have been converted to space on the forum.


0

Response Number 7
Name: ddan
Date: September 8, 2009 at 18:19:11 Pacific
Reply:

Hi...thanks for your continued help with this!

So I put the ECHO before the stsadm cmd and then changed the space after the = to be a tab. Still an issues exists, see below

***********************************************
E:\MySites>mysites.bat
ECHO is on.

E:\MySites>for /F "tokens=1-3 delims= " %a in (users_tabDel.txt) do ECHO(

E:\MySites>ECHO(


E:\MySites>stsadm -o createsite -url http://my-site-stg.company.com/pers...
a -ownerlogin DOMAIN\%b -owneremail %c@company.com

The user or group 'DOMAIN\%b' is unknown.

E:\MySites>
*******************************************************

I can convert the tab-del txt file to comma separated if it will make it easier? pls advise

thanks again!


0

Response Number 8
Name: ddan
Date: September 9, 2009 at 00:10:02 Pacific
Reply:

Hi Guys...any ideas on the above? been trying to solve it to no avail...your help is much appreciated...


0

Response Number 9
Name: Judago
Date: September 9, 2009 at 00:32:41 Pacific
Reply:

I'm just going to re-post M2's script inside pre tags because the
way the url gets truncated is not helpful:

for /f "tokens=1-3 delims=	" %%a in (myfile) do (
stsadm -o createsite -url http://my-site.company.com/personal/%%a -ownerlogin domain\%%b -owneremail %%c
)

I realy can't see anything wrong with it...


0

Response Number 10
Name: Gaetano
Date: September 9, 2009 at 03:21:23 Pacific
Reply:

Is Tab a default limiting character? Editing Mechanix2Go's script:

@echo off & setLocal EnableDELAYedExpansion

for /f "tokens=1-3" %%a in (myfile) do (
stsadm -o createsite -url <a href="http://my-site.company.com/personal/%%a" target="_blank">http://my-site.company.com/personal...</a> -ownerlogin domain\%%b -owneremail %%c
)

If it doesn't work try to convert the tab-del txt file to comma separated one and execute this:

@echo off & setLocal EnableDELAYedExpansion

for /f "tokens=1-3 delims=," %%a in (myfile) do (
stsadm -o createsite -url <a href="http://my-site.company.com/personal/%%a" target="_blank">http://my-site.company.com/personal...</a> -ownerlogin domain\%%b -owneremail %%c
)

Gaetano

PS: correct the stsadm before copying it: I can't avoid the catching of the url...


0

Response Number 11
Name: Mechanix2Go
Date: September 9, 2009 at 10:04:16 Pacific
Reply:

The default delims are space & tab.


=====================================
Helping others achieve escape felicity

M2


0

Response Number 12
Name: Gaetano
Date: September 9, 2009 at 13:44:52 Pacific
Reply:

So I don't need to use any delimiter:

 for /f "tokens=1-3" 
it's all I need, don't I?

0

Response Number 13
Name: ddan
Date: September 9, 2009 at 18:37:46 Pacific
Reply:

Hi Guys...

Still having trouble...so ive tried all of the above in various combos and still gettign same results. Maybe im doing something wrong...not sure.

But here is what is in the cmd window:
**********************************
E:\MySites>mysites.bat
ECHO is on.

E:\MySites>for /F "tokens=1-3 delims=," %a in (users_tabDel.txt) do ECHO(

E:\MySites>ECHO(


E:\MySites>stsadm -o createsite -url href="http://my-site-stg.company.com/per
sonal/%a" target="_blank" -ownerlogin DOMAIN\%b -owneremail %c@company.com 0<a 1>
http://my-site.company.com/personal/a
The system cannot find the file specified.
E:\MySites>
**************************************************
Here is exactly what I have in the batch file:
***************************************************
@echo & setLocal EnableDELAYedExpansion

for /f "tokens=1-3 delims=," %%a in (users_tabDel.txt) do ECHO(
stsadm -o createsite -url http://my-site.company.com/personal/a -ownerlogin DOMAIN\%%b -owneremail %%c@company.com
)
*******************************************************
and here is what I have in the txt file:
(only one line for the moment whilst testing)
********************************************************
username,username,firstname.lastname
*********************************************************

Thanks!


0

Response Number 14
Name: ddan
Date: September 9, 2009 at 20:44:26 Pacific
Reply:

Guys thanks for all your help, got it licked finally!

so this is what worked in the end:
**************************************************
@echo on

FOR /f "tokens=1-3" %%a in (e:\mysites\sites.txt) do @stsadm -o createsite -url http://my-site.company.com/personal... -ownerlogin "DOMAIN\%%b" -owneremail "%%c@company.com"

@echo off

**************************************

Thanks for all your help!...much appreciated!!


0

Response Number 15
Name: ddan
Date: September 9, 2009 at 20:50:11 Pacific
Reply:

Oh and as you can see, seems it was the " " around the domain\... and around the email that did it in the end...

thx


0

Response Number 16
Name: Mechanix2Go
Date: September 9, 2009 at 22:27:08 Pacific
Reply:

No idea why you're using echo on. [It's already on.] Nor why you're using echo off at the end.

And %%a never gets used. LOL

But if it blows your dress up, I'm all for it.


=====================================
Helping others achieve escape felicity

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Multiple arguments froma txt file

Append Multiple .txt files (batch) www.computing.net/answers/programming/append-multiple-txt-files-batch/14557.html

Batch created multiple .txt files www.computing.net/answers/programming/batch-created-multiple-txt-files/17905.html

Read and write txt files online www.computing.net/answers/programming/read-and-write-txt-files-online/19406.html