Page 1 of 1

Read a file by line by line and store some specific values in another text file through bat file

Posted: 12 Jan 2018 04:18
by naraen87
Say for Example

I'm having my sample.txt file as

Code: Select all

Environment=non-clusters
Server1=xx.xx.xx.xxx
Server2=xx.xx.xx.xxx
GDrvie_Build=\\xx.xx.xx.xxx\Users\vissas\Desktop\WIServerSetup\CAM8\CAM8_6.20.8.2
Build_Artifact_File=Hotfix_CAM8_6.20.8.2.7z
Newer_Version=UAT2_v6.18.13.1
Property_File_Name=MCSysProp.properties
Property_File_Location=C:\narayana\Enviromnet_Setup\WIServerSetup\UAT\MDrive\BaNCSFS\BancsProduct\Intranet\properties\InputFiles
Xml_File_Location=C:\narayana\Enviromnet_Setup\WIServerSetup\UAT\MDrive\BaNCSFS\BancsProduct\Extranet\Bancs.ear\Bancs.war\WEB-INF
Common_Path_For_Extraction=Users\Public
7zip_exe_Location="C:\Program Files\7-Zip\7z.exe"

From the above file I need only the data exists after = in a new file, my new created file needs to look like the below one

Code: Select all

non-clusters
xx.xx.xx.xxx
xx.xx.xx.xxx
\\xx.xx.xx.xxx\Users\vissas\Desktop\WIServerSetup\CAM8\CAM8_6.20.8.2
Hotfix_CAM8_6.20.8.2.7z
UAT2_v6.18.13.1
MCSysProp.properties
C:\narayana\Enviromnet_Setup\WIServerSetup\UAT\MDrive\BaNCSFS\BancsProduct\Intranet\properties\InputFiles
C:\narayana\Enviromnet_Setup\WIServerSetup\UAT\MDrive\BaNCSFS\BancsProduct\Extranet\Bancs.ear\Bancs.war\WEB-INF
Users\Public
"C:\Program Files\7-Zip\7z.exe"

Re: Read a file by line by line and store some specific values in another text file through bat file

Posted: 12 Jan 2018 08:47
by Squashman
So you already know how to read a file line by line with the FOR /F command based on the advice you were given at StackOverFlow.

Now all you need to do is add to that code. The DELIMS option allows you to break up the line into multiple variables known as TOKENS to the FOR command. In your case you are asking for the second token that is delimited by an equals symbol.

Code: Select all

FOR /F "tokens=2 delims==" %%G IN (propertyfile.txt) do echo %%G >>newpropertyfile.txt

Re: Read a file by line by line and store some specific values in another text file through bat file

Posted: 17 Jan 2018 04:44
by naraen87
Thanks for your reply @Squashman. It working perfectly awesome.