We have a file named parameters.txt which contains in comma separated value:
db.hostname,db.username,db.password,db.url,db.status,codesettingsA, codesettimgsB
Also, we have a main file called properties.txt which contains in Line format
db.hostname=hostname
db.username=username
db.password=password
I need to pass the comma separated values in parameters.txt and check whether if it is exist in properties.txt. If it is not exist it should print bottom of the properties.txt
For Example, in the properties.txt: db.url, db.status, codesettingsA and codesettimgsB is not there. However, I’m passing from the parameters.txt. It should be appended and the result should be like this in properties.txt:
db.url
db.status
codesettingsA
codesettimgsB
Note: Already values are declared for db.hostname=hostname, db.username=username and db.password=password in properties file. I'm passing db,hostname,db.username,db.password from parameter file. So, this should ignore the values even after the comma and shouldn't print db,hostname,db.username,db.password
Is there any ways to print them at the bottom page of properties.txt? Can you provide sample code?
You can use this awk:
Output:
Try this :
Parameters are parsed and stored into a
params
array.For each parameter, the loop checks if it's present in properties.txt and, if not, append it at the bottom of the file.