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.
This works with any number of dots and hyphens in the line and does **not** require GNU sed:

```
sed 'h; s/.*=//; x; s/=.*//; s/[.-]/_/g; G; s/\n/=/'  < data

```

Here's how:

* h: save a copy of the line in the hold space
* s: throw away everything before the equal sign in the pattern space
* x: swap the pattern and hold
* s: blow away everything after the `=` in the pattern
* s: replaces dots and hyphens with underscores
* G: join the pattern and hold with a newline
* s: replace that newline with an equal to glue it all back together