Multiple arguments froma txt file

September 7, 2009 at 19:26:56
Specs: win2K3
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!


See More: Multiple arguments froma txt file

Report •


#1
September 7, 2009 at 20:03:13
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


Report •

#2
September 7, 2009 at 21:09:02
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!


Report •

#3
September 7, 2009 at 22:31:25
@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


Report •

Related Solutions

#4
September 7, 2009 at 23:34:12
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?


Report •

#5
September 8, 2009 at 01:09:34
Use the script I posted but put ECHO before the stsadm. Then run it and paste the output.


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

M2


Report •

#6
September 8, 2009 at 01:48:13
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.


Report •

#7
September 8, 2009 at 18:19:11
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!


Report •

#8
September 9, 2009 at 00:10:02
Hi Guys...any ideas on the above? been trying to solve it to no avail...your help is much appreciated...

Report •

#9
September 9, 2009 at 00:32:41
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...


Report •

#10
September 9, 2009 at 03:21:23
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...


Report •

#11
September 9, 2009 at 10:04:16
The default delims are space & tab.


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

M2


Report •

#12
September 9, 2009 at 13:44:52
So I don't need to use any delimiter:
 for /f "tokens=1-3" 
it's all I need, don't I?

Report •

#13
September 9, 2009 at 18:37:46
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!


Report •

#14
September 9, 2009 at 20:44:26
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!!


Report •

#15
September 9, 2009 at 20:50:11
Oh and as you can see, seems it was the " " around the domain\... and around the email that did it in the end...

thx


Report •

#16
September 9, 2009 at 22:27:08
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


Report •


Ask Question