3

I am new to shell scripting. And trying to create a .ini file with following details. End result of .ini file:

[dev]
JDBC_URL = jdbc:h2:mem:mem_test;MODE=Oracle
JDBC_USERNAME =
JDBC_PASSWORD =

SERVICE_ENDPOINT = http://localhost:8080/Central/api/AppService

[qa]
JDBC_URL = jdbc:oracle:thin:@qa-oracle:1521:qa
JDBC_USERNAME = qauser
JDBC_PASSWORD = qapass

SERVICE_ENDPOINT = http://qa-services/Central/api/AppService

[prod]
JDBC_URL = jdbc:oracle:thin:@prod-oracle:1521:prod
JDBC_USERNAME = scott
JDBC_PASSWORD = tiger

SERVICE_ENDPOINT = http://prod-services/Central/api/AppService

How to start with creating .ini file using bash. You can also suggest with some example, if their is some other way in bash using template to do same.

5
  • This might help: Create new file from templates with bash script Commented Mar 31, 2018 at 18:30
  • @Cyrus, i already had a look on this, but it doesn't solve my purpose as i am looking for creating multi section file with common fields in each seaction. And by section i mean dev, qa, prod. Commented Mar 31, 2018 at 18:36
  • @BleedCode, why don't you crate a property file eg--> JDBC_URL, JDBC_USERNAME,JDBC_pass and URL etc and then provide values there, you could easily use while or awk to read that file and could create these kind of files then, let me know on same if that is what you are looking for? Commented Mar 31, 2018 at 18:40
  • I tried creating a property file using template, but with that option also i am not able to create sections. @RavinderSingh13 .If you have any example on same you can share that would be a great help. Commented Mar 31, 2018 at 18:44
  • @BleedCode, I tried in a while script please check and let me know, though I am not sure about your requirement fully. Commented Mar 31, 2018 at 19:02

1 Answer 1

0

Let's say you create following property Input_file.

cat Input_file
dev,bla-bla-bla,user_singh,singh,http://chumma.com
qa,bla-bla-bla,user_singh1,http://chumma1.com

It's value are in format of environment,JDBC_URL,user,pass,service_point Then following may help you on same.

while IFS=, read environment jdbc_url user pass service
do
   echo -e "[" $environment "]\nJDBC_URL = $jdbc_url\nJDBC_USERNAME = $user\nJDBC_PASSWORD = $pass\nSERVICE_ENDPOINT = $service"
done < "Input_file"
Sign up to request clarification or add additional context in comments.

6 Comments

But echo won't prints the value in properties file. It prints on console.
@BleedCode, you mean you need to create a single output file or multiple output files?
One template file using which one properties file should be created with above content which i provided in example.
@BleedCode: Replace "Input_file" with "Input_file" > "properties.ini" to redirect stdout to a file.
@RavinderSingh13 in bash we have a template for creating properties file. For more understanding go through this: Create new file from templates with bash script". So my question is same but i need a template with multiple sections.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.