Computing.Net > Forums > Windows XP > problem -Batch file for taking text

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.

problem -Batch file for taking text

Reply to Message Icon

Name: hunny
Date: February 15, 2008 at 01:18:34 Pacific
OS: XP
CPU/Ram: 256
Product: ibm
Comment:

Hi
In my case i want to read a text file in such a way like that it will take the first line form the text and forward it to the vss

text is like
file name file path
A B
C d

and i want to forward it as B/A for he first line and then it comes to second line to take the other path
After Path is seperated from file name by a SpaceBAR and other files by an enter


himanshu



Sponsored Link
Ads by Google

Response Number 1
Name: hunny
Date: February 15, 2008 at 03:07:52 Pacific
Reply:

guys i need your help

himanshu


0

Response Number 2
Name: IVO
Date: February 15, 2008 at 03:21:34 Pacific
Reply:

Try to explain what you want to achieve in plain words and as exactly as possible.

English isn't my mothertongue, but your post is really cryptic.


0

Response Number 3
Name: hunny
Date: February 15, 2008 at 03:35:20 Pacific
Reply:

i need a program which will take data from text file and in textfile i have data in this manner
file_name file_path
A B
C d
it means for first file file name is'A' file path is 'B'.
the program should read the text and give me output as 'B/A' which i need to use in my operation.Then it will read the next file and give me output as 'd/C' this process is repeated till all the files are processed

Please tell if you do it because i have very little knowledge about batch files but i need to make this program for my operation

himanshu


0

Response Number 4
Name: IVO
Date: February 15, 2008 at 03:52:16 Pacific
Reply:

@Echo Off> fileout.txt
For /F "tokens=1-2" %%a in (filein.txt) Do (
Echo.%%b/%%a>> fileout.txt)

This works if file_name and file_path have no embedded spaces. If the first line is the header replace "tokens=1-2" with "skip=1 tokens=1-2".

Let me know if what posted works. I'll be back 1 hour later.


0

Response Number 5
Name: hunny
Date: February 15, 2008 at 04:18:19 Pacific
Reply:

hi
Thanks a lot it is coming but can i redirect this output i.e. in fileout.Because i need this output 'b/a' in vss command so that i can locate this files in vss server
Its command is ss checkout b/a..i want this b/a from fileout.txt
Please tell me if you can do this

himanshu


0

Related Posts

See More



Response Number 6
Name: IVO
Date: February 15, 2008 at 05:06:16 Pacific
Reply:

Please, first confirm me the pathname/filename output from my script is correct (no spaces in path/file), then explain what you mean by "vss command format" as this notation is unknown to me.

Do you want each output path/file line be executed as a command statement while the text file is read or stored in executable format in an output file for a later process?

In both cases specify the exact format of the command line that embeds the path/file data.

Otherwise tell me what you want as output.


0

Response Number 7
Name: hunny
Date: February 15, 2008 at 05:32:20 Pacific
Reply:

hi
see yes your script was right it is giving right output.I have to automate some part of visual source safe for that i need path/file as input in command "ss checkout <path/file>".
Now what ever output we are getting i have to redirect it to the above command.


himanshu


0

Response Number 8
Name: IVO
Date: February 15, 2008 at 05:52:06 Pacific
Reply:

@Echo Off
Echo.@Echo Off > ssexec.bat
For /F "tokens=1-2" %%a in (filein.txt) Do (
Echo.ss checkout %%b/%%a>> ssexec.bat)

The above batch generates the ssexec.bat holding on each line the command

ss checkout path/file (from the filein.txt)

You can start the ssexec script by typing at prompt

ssexec

after the first sript ends or you can add the above line at the end of the native script to trigger it automatically.

Please report if I have understood your wish.


0

Response Number 9
Name: hunny
Date: February 18, 2008 at 01:02:20 Pacific
Reply:

Yes sir thanks a lot you have completly understood,now can you please tell me if i can take input from user,in the code you have taken filein.txt as input if i want to take input from user like in which file they have stored information

himanshu


0

Response Number 10
Name: IVO
Date: February 18, 2008 at 02:39:10 Pacific
Reply:

Here is the interactive version of the script self-triggering the ssexec script (the filename must not embed blanks, otherwise a more complex script is needed)

@Echo Off
:LOOP
Echo. Please enter the file name to be processed.
Set FileIn=
Set /P FileIn=^>
If not exist %FileIn% (
Echo.File %FileIn% does not exist.
GoTo :LOOP
)
Echo.Reading %FileIn%
Echo.@Echo Off > ssexec.bat
For /F "tokens=1-2" %%a in (%FileIn%) Do (
Echo.ss checkout %%b/%%a>> ssexec.bat)

call ssexec
Del ssexec.bat
Set FileIn=
:: End_Of_Batch


0

Response Number 11
Name: hunny
Date: February 18, 2008 at 04:10:33 Pacific
Reply:

Hi that is fine but can you please tell me why you have written Set /P FileIn=^>"additional operators"after equal to sign.
see my dos path is C:/program files/mvss

and my files are in c:/test/<filename>
If not exist c:/test/%FileIn%.txt(
Echo.File %FileIn% does not exist.
GoTo :LOOP

then it is giving syntax error

himanshu


0

Response Number 12
Name: IVO
Date: February 18, 2008 at 05:10:38 Pacific
Reply:

First the ^> symbol.

the Set /P syntax states

Set /P <var_name>=[string]

where string is an optional message to be displayed in front of the cursor waiting for user's input. So ^> mimics the raw prompt showing the script is waiting for input.
If you want to replicate the NT (NOT DOS) prompt you have to code

Set /P FileIn=%CD%^>

but now you can't say if the prompt is issued by the script or OS.

The error you get is due to the lack of space between %FileIn%.txt and the left parenthesis (.


0

Response Number 13
Name: hunny
Date: February 18, 2008 at 06:47:01 Pacific
Reply:

hi now its working.Well i dont whether it will be complicated or not
but right now i am getting output as
ss checkout b/a
ss checkout d/c

can i get output as ss checkout b/a d/c f/e soo on.

himanshu


0

Response Number 14
Name: IVO
Date: February 18, 2008 at 07:06:39 Pacific
Reply:

Technically yes, but actually that is not reccommanded as the command line has a limit of 127 chars and the variable to be set up for the purpose may even exceed reasonable size.

Maybe the ss command allows a parameter to read directly from a file but I don't know its syntax; you may try ss /? to display an on-line help.


0

Response Number 15
Name: hunny
Date: February 18, 2008 at 23:27:43 Pacific
Reply:

If i dont bother about the limit of 127 char then can we do anything like that.See first output should be like "a/b d/f/ e/f" and so on..donot take ss into consideration then this output can be used to run "ss checkout a/b d/f/ e/f"

if you can do this then that will be better

himanshu


0

Response Number 16
Name: IVO
Date: February 19, 2008 at 02:17:58 Pacific
Reply:

The following script works as you wish; it stacks into the variable "tail" the processed output from the input file.

Then you can run directly ss checkout using "tail" as parameter or have the variable stored into the sstail.txt file holding just one long line.

To store a whole file into one variable is anyway a risky behavior that may cause unpredictable results.

@Echo Off
SetLocal EnableDelayedExpansion

:LOOP
Echo.Please enter the file name to be processed.
Set FileIn=
Set /P FileIn=^>
If not exist %FileIn% (
Echo.File %FileIn% does not exist.
GoTo :LOOP)

Echo.Reading %FileIn%
Set tail=
For /F "tokens=1-2" %%a in (%FileIn%) Do (
Set tail=!tail! %%b/%%a)

Echo.%tail%> sstail.txt
ss checkout %tail%
:: End_Of_Batch


0

Response Number 17
Name: hunny
Date: February 21, 2008 at 05:05:14 Pacific
Reply:

hi
can you tell how can we get a particular word from the text which is there in first line of the text
e.g
qwerty
asdfgh
cvbn

this is the text and i need only word 'r' from the first linerest i dont need .Can we do that?

himanshu


0

Response Number 18
Name: IVO
Date: February 21, 2008 at 09:19:22 Pacific
Reply:

Do you want to extract a particular word from the first line of a text file (e.g.

my girl is a nice blondie CR/LF

extract girl)?

As in your post "r" is a character not a word.


0

Response Number 19
Name: hunny
Date: February 22, 2008 at 01:10:51 Pacific
Reply:

hi that problem was solved but i realy need to solve this problem can we use if condition in for loop?if i cant use then how can we solve this problem.


@echo off
set a=
for /F "tokens=1,2*" %%i in (myfile.txt) do (
echo.%%j/%%i
echo.%%k
set a=%%k
if %a%==2 (echo yes) else (echo no)
)
it is giving error as
(echo was unexpected at this time


myfile.txt contain
a a 1
s d 2

Output should be like
first it should give no then yes


himanshu


0

Response Number 20
Name: IVO
Date: February 22, 2008 at 03:22:53 Pacific
Reply:

The error you get is due to the misuse of variables inside a compound statement, i.e. a statement requiring parenthesis to mark a "command sequence".

In that case the variable is expanded with the value it has BEFORE the sequence's begin and never changed, so you get nul for a at IF time.

To avoid that you have to enable the "delayed expansion" and then use dynamic variables marked by ! instead the usual %.

So your script becomes

@echo off
SetLocal EnableDelayedExpansion

set a=
for /F "tokens=1,2*" %%i in (myfile.txt) do (
echo.%%j/%%i
echo.%%k
set a=%%k
if "!a!"=="2" (echo yes) else (echo no)
)

and better always to embrace the variable with " when performing an IF statement.


0

Response Number 21
Name: IVO
Date: February 22, 2008 at 08:48:23 Pacific
Reply:

Don't post in the DOS forum questions that have nothing to do with DOS: the script you are coding is NT batch interpreted by cmd.exe not command.com.

There is no DOS in Windows NT/2000/XP as they are NT kernel operating systems; what looks like the DOS prompt is NT console and the system just offers an emulator for legacy DOS applications, NTVDM aka NT Virtual DOS Machine.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: problem -Batch file for taking text

Batch File reading a Text File www.computing.net/answers/windows-xp/batch-file-reading-a-text-file/153554.html

batch file for time delay in xp www.computing.net/answers/windows-xp/batch-file-for-time-delay-in-xp/78216.html

batch file for permissions www.computing.net/answers/windows-xp/batch-file-for-permissions/170216.html