linux - Text manipulation with bash -


i have bash variables defined in file:

var1=.... var2="some value" var3=.... .... 

how can change value of variable , add 1 more variable in specific line? need in single shell script.

edit:

expected output is:

var1=.... var2="another value" var3=.... new_var=.... .... 

i believe following code achieve results want, if understood question correctly:

#!/bin/bash  #change value of variable sed -i -e 's/^var2=.*$/var2="another-value"/gi' /folder/file  #add new variable variable declaration area, using 1 existing variable reference point sed -i -e '/^var2=/i \new_var="another-value"' /folder/file  exit 0 

that substitute value of variable , add new variable list using 1 existing variable reference point insert new variable. code work in many bash versions.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -