| 1. |
Solve : Get a substring from the file? |
|
Answer» I have one file 'filename.txt' which have contents like set var='SHCS112.txt' Where did the SINGLE quotes come from? Although they would not prevent the batch file from functioning properly there is no mention of them in the original post. It should be echo !var! due to the delayed expansion 8-)Hi, This is my screen shot of my command window. ------------------------------------------------------------------------ C:\>setlocal enabledelayedexpansion C:\>set var=SHCS112.txt C:\>set var=!var:~2,2! C:\>echo !var! !var! ------------------------------------------------------------------------- My result is !var! Please help me in solving this as I am new to WRITING Batch Script. Cut and Paste this code into your favorite editor (notepad works just fine): Code: [Select]@echo off setlocal enabledelayedexpansion for /f %%i in (filename.txt) do ( set var=%%i set var=!var:~2,2! if !var!==CS echo %%i >> cs_files.txt if !var!==CQ echo %%i >> cq_files.txt ) Save the file with any name you choose but be sure to give it a .bat EXTENSION. You can then run the file you SAVED from the command line. 8-)Hi, Thanks a lot for guiding me. Its really awesome. I got the exact result. This is really a wonderful site which makes me do the task easily. Thanks a lot! Thanks a lot!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|