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.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Srishti
  • 355
  • 1
  • 17
  • This might help: [Create new file from templates with bash script](https://stackoverflow.com/q/6214743/3776858) – Cyrus Mar 31 '18 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. – Srishti Mar 31 '18 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? – RavinderSingh13 Mar 31 '18 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. – Srishti Mar 31 '18 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. – RavinderSingh13 Mar 31 '18 at 19:02

1 Answers1

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"
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
  • But echo won't prints the value in properties file. It prints on console. – Srishti Mar 31 '18 at 19:07
  • @BleedCode, you mean you need to create a single output file or multiple output files? – RavinderSingh13 Mar 31 '18 at 19:07
  • One template file using which one properties file should be created with above content which i provided in example. – Srishti Mar 31 '18 at 19:12
  • @BleedCode, sorry didn't get it please be more clear on it. – RavinderSingh13 Mar 31 '18 at 19:24
  • 1
    @BleedCode: Replace `"Input_file"` with `"Input_file" > "properties.ini"` to redirect stdout to a file. – Cyrus Mar 31 '18 at 19:55
  • 1
    @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. – Srishti Apr 01 '18 at 02:28