Computing.Net > Forums > Windows 2000 > Parsing a file using batch commands

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.

Parsing a file using batch commands

Reply to Message Icon

Name: v_ajay31
Date: June 27, 2007 at 23:39:56 Pacific
OS: win2k + sp4
CPU/Ram: 256 MB
Comment:

Please help me in writing a batch file which parses a text file sample.txt and prints some tokens.
contents of sample.txt
user_db ADMINS_CAS_SENS Y
user_db ADMIN_USER_REQ N
user_db ADMIN_FILE_REQ N
user_db OLD_PASSWORD N

I want something like:

if token==ADMINS_CAS_SENS
print the corresponding Y or N
else if token==OLD_PASSWORD
print the corresponding Y or N
else if token==OLD_PASSWORD
print the corresponding Y or N
I could parse the file but I am failing to comapre string.
The code I have written is:
for /f "tokens=1,2,3 delims= " %%a in (sample.txt) do (
if %%b==ADMINS_CAS_SENS (
echo %c
) else (
echo %%a
)
Though it's not complete.
Thanks in advance!



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: June 29, 2007 at 01:40:57 Pacific
Reply:

I suggest you avoid nested If as they become soon unreadable. So the following code performs what you want in cleaner and more friendly way.

@Echo Off
For /f "tokens=2,3 delims= " %%a in (sample.txt) Do (
If "%%a"=="ADMINS_CAS_SENS" Echo %%a %%b
If "%%a"=="OLD_PASSWORD" Echo %%a %%b
)


0

Response Number 2
Name: v_ajay31
Date: June 29, 2007 at 03:45:47 Pacific
Reply:

It resolved my problem, thank you so much.


0

Response Number 3
Name: v_ajay31
Date: July 2, 2007 at 03:34:29 Pacific
Reply:

Hi,
I have one more query. I have some code:
If "%%a"=="FILE_PATH" echo File Path is: %%b
My problem is variable %%b has value "%path%\bin\f_ocx.txt" here path is an environment variable. So in order to print the whole path, path varible should be resolved. Current output- File Path is: %path%\bin\f_ocx.txt
Expected output- File Path is: c:myDirs\old_docs\bin\f_ocx.txt

Thanks in advance.


0

Response Number 4
Name: v_ajay31
Date: July 2, 2007 at 05:55:36 Pacific
Reply:

I found the solution. Please ignore the above query!
-Thanks


0

Response Number 5
Name: Mechanix2Go
Date: July 3, 2007 at 04:39:16 Pacific
Reply:

It often helps others to say what the solution is.


=====================================
If at first you don't succeed, you're about average.

M2



0

Related Posts

See More



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 2000 Forum Home


Sponsored links

Ads by Google


Results for: Parsing a file using batch commands

naming a file using current time in www.computing.net/answers/windows-2000/naming-a-file-using-current-time-in/54146.html

change a line in a file using CMD www.computing.net/answers/windows-2000/change-a-line-in-a-file-using-cmd/63947.html

Creat text file useing batch comman www.computing.net/answers/windows-2000/creat-text-file-useing-batch-comman/42410.html