Question: 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_numbers
my.variable.another.var2=another-long-ling.with.lot_of_different:characters:and_numbers
my.variable.number3=yet_another_long-ling.with.lot_of_different:characters:and_numbers

```

First 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_numbers
my.variable.another.var2=another-long-ling.with.lot_of_different:characters:and_numbers
my.variable.number3=yet_another_long-ling.with.lot_of_different:characters:and_numbers

```

to

```
my_variable_var1=a-long-ling.with.lot_of_different:characters:and_numbers
my_variable_another_var2=another-long-ling.with.lot_of_different:characters:and_numbers
my_variable_number3=yet_another_long-ling.with.lot_of_different:characters:and_numbers

```

using any of those cool 'one liners'? Would love to use that, plus a good learning.

Answer: 
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}'

```
Using `bash`:

```
while IFS='=' read -r i j; do echo "${i//./_}=$j" ; done

```

We have used parameter expansion pattern `${i//./_}` to replace all `.`s with `_`s in the variable name.

**Example:**

```
$ cat file.txt 
my.variable.var1=a-long-ling.with.lot_of_different:characters:and_numbers
my.variable.another.var2=another-long-ling.with.lot_of_different:characters:and_numbers
my.variable.number3=yet_another_long-ling.with.lot_of_different:characters:and_numbers

$ while IFS='=' read -r i j; do echo "${i//./_}=$j" ; done <file.txt 
my_variable_var1=a-long-ling.with.lot_of_different:characters:and_numbers
my_variable_another_var2=another-long-ling.with.lot_of_different:characters:and_numbers
my_variable_number3=yet_another_long-ling.with.lot_of_different:characters:and_numbers

```