Name: ajay Date: September 5, 2007 at 08:16:45 Pacific Subject: File parsing and for loop OS: win2k + sp4 CPU/Ram: 128KB
Comment:
I have written a batch script but not getting desired output. Following is the script: ********************* @echo off setlocal For /f "tokens=1,2,3,4,5 delims= " %%a in (data.txt) Do ( If "%%b"=="MS_TYPE" ------------------- If "%%b"=="MS_TYPE" Echo Module Type %%c for /f "tokens=4,5,6,7,8,9 delims=,> " %%i in (version.txt) do ( If "%%i"=="%%c" Echo Module Version: %%n ) If "%%b"=="MS_TYPE" Echo Module-Name: %%a If "%%b"=="DEFAULT_VAL" Echo Default value is: %%c ) endlocal ********************** file data.txt - my_db1 MS_TYPE Online my_db1 DEFAULT_VAL Y my_db1 DESCRIPTION sam_des1 my_db1 INTERVAL 30 my_db1 MS_TYPE Online my_db1 DEFAULT_VAL Y my_db1 DESCRIPTION sam_des12 my_db1 INTERVAL 40 my_db1 MS_TYPE Online my_db1 DEFAULT_VAL Y my_db1 DESCRIPTION sam_des14 my_db1 INTERVAL 60 my_db2 MS_TYPE LocalSystem my_db2 DEFAULT_VAL N my_db2 DESCRIPTION sam_des2 my_db2 INTERVAL 10 file version.txt - For Module <my_db1 Online>, version of Module is 4.0.0
For Module <local LocalSystem>, version of Module is 5.0.00
For Module <my_db2 Online>, version of Module is 4.0.0 For Module <my_db3 Online>, version of Module is 4.0.0
I need the data version vise. I need following output:- Module Type Online Module Version: 4.0.0 Module-Name: my_db1 Default value is: Y -------------- Module-Name: my_db2 Default value is: Y ------------- Module Type Online Module-Name: my_db3 Default value is: Y ------------------ Module Type LocalSystem Module Version: 5.0.00 Module-Name: local Default value is: N I am working on it for 3-4 days but couldn't fix it. If anyone helps, it will be really great.
In the previous message please change desired output: ....... [Module Type Online] remove this line Module-Name: my_db3 ...... by mistake I had written that. Actually what I need is version and module type should be printed once and then all modules under that version/type.
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE