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
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!
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.
Summary: how do i do the same as this, naming a file using the current date except i want to use current time instead of date ,in a batch file TEST_%Date:~-4,4%%Date:~-10,2%%Date:~-7,2%.txt ...
Summary: i have a file named (whatever) that contains of many lines but i want to change the third line (that contains " SMTP server=naeln.test.com " to "SMTP server= naeln.again.test.com" how do i do that us...
Summary: I m trying to learn batch programing. I want creat one text file with type some text lines useing batch file. File name will be NAIM.TXT. I know COPY CON command but when u type copy con filename comm...