I want to read a property file like below and get the particular key value bash
My properties file looks like oop
name=Chenjo.net version=1.0.2 date=24/March/2010
I want to get the version from the properties file. You can do this by various methods. this
Using Type function: .net
C:\Users\Chenjo\Desktop>type test.properties | find "version"
There is a disadvantage with this method you could not store that value in a variable. code
Using For Loop: token
C:\Users\Chenjo\Desktop>FOR /F %i IN (test.properties) DO echo %i
Using this command you can read that file line by line. ci
FOR /F "eol=; tokens=2,2 delims==" %i IN (test.properties) DO echo %i
Using this commend you can get the values only. get
eol is End of Line input
tokens is specifying which tokens are displayed – 2,2 means only the second token will be displayed string
delims is the deliminator. This is the separator
FOR /F "eol=; tokens=2,2 delims==" %i IN ('findstr /i "version" test.properties') DO set version=%i
Using findstr we get the correct string from the properties file and give as an input to the for loop.
That for loop processes the result and set that value to the variable version.
findstr /i means it is not a case sensitive one.
Using echo you can get the value.
echo %version%
When using it in a bat, add a % befor %i. That is like
FOR /F "eol=; tokens=2,2 delims==" %%i IN ('findstr /i "version" test.properties') DO set version=%%i echo %version%