I need to be able to export some variables from a file, so that I can use it in my BASH script. the file content is something like this:my.variable.var1=a-long-ling.with.lot_of_different:characters:and_numbersmy.variable.another.var2=another-long-ling.with.lot_of_different:characters:and_numbersmy.variable.number3=yet_another_long-ling.with.lot_of_different:characters:and_numbersFirst I tried sourcing it using source as they are and got the error message saying: command not found. I tried using export, which gave me error message saying: not a valid identifier.I think I can only export if I change my variable from my.variable.var1 to my_variable_var1.I am able to do this by cutting the line at = and then replacing all .s with _s and then adding the variables back.So my question is, is it possible to change:my.variable.var1=a-long-ling.with.lot_of_different:characters:and_numbersmy.variable.another.var2=another-long-ling.with.lot_of_different:characters:and_numbersmy.variable.number3=yet_another_long-ling.with.lot_of_different:characters:and_numberstomy_variable_var1=a-long-ling.with.lot_of_different:characters:and_numbersmy_variable_another_var2=another-long-ling.with.lot_of_different:characters:and_numbersmy_variable_number3=yet_another_long-ling.with.lot_of_different:characters:and_numbersusing any of those cool 'one liners'? Would love to use that, plus a good learning.
Replace all instances of a character if it occurres before another character
bash;text processing
With sed:sed -e :1 -e 's/^\([^=]*\)\./\1_/;t1'That is replace a sequence of characters other than . at the beginning of the line followed by . by that same sequence and _, and repeat the process until it no longer matches.With awk:awk -F = -v OFS== '{gsub(/\./, _, $1); print}'Now, in case the right hand side of the = contains characters special to the shell (\$&();'#~<>...`, space, tab, other blanks...), you may want to quote it:sed s/'/'\\\\''/g;:1'     s/^\([^=]*\)\./\1_/;t1'     s/=/='/;s/\$/'/Or:awk -F = -v q=' -v OFS== '   {gsub(q, q \\ q q)    gsub(/\./, _, $1)    $2 = q $2    print $0 q}'