Question: I'd like to use `sed` to process a property file such as:

```
java.home=/usr/bin/java
groovy-home=/usr/lib/groovy
workspace.home=/build/me/my-workspace

```

I'd like to replace the `.`'s and `-`'s with `_`'s but only up to the `=`'s token. The output would be

```
java_home=/usr/bin/java
groovy_home=/usr/lib/groovy
workspace_home=/build/me/my-workspace

```

I've tried various approaches including using addresses but I keep failing. Does anybody know how to do this?

Answer: 
What about...

```
$ echo foo.bar=/bla/bla-bla | sed -e 's/\([^-.]*\)[-.]\([^-.]*=.*\)/\1_\2/'
foo_bar=/bla/bla-bla

```

This won't work for the case where you have more than 1 dot or dash one the left, though. I'll have to think about it further.
Other way using sed

```
sed -re 's/(.*)([.-])(.*)=(.*)/\1_\3=\4/g' temp.txt

```

Output

```
java_home=/usr/bin/java
groovy_home=/usr/lib/groovy
workspace_home=/build/me/my-workspace

```

In case there are more than `.-` on left hand side then this

```
sed -re ':a; s/^([^.-]+)([\.-])(.*)=/\1_\3=/1;t a' temp.txt

```