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: 
**awk** makes life easier in this case:

```
awk -F= -vOFS="=" '{gsub(/[.-]/,"_",$1)}1' file

```

here you go:

```
kent$  echo "java.home=/usr/bin/java
groovy-home=/usr/lib/groovy
workspace.home=/build/me/my-workspace"|awk -F= -vOFS="=" '{gsub(/[.-]/,"_",$1)}1'
java_home=/usr/bin/java
groovy_home=/usr/lib/groovy
workspace_home=/build/me/my-workspace

```

if you really want to do with sed (**gnu sed**)

```
sed -r 's/([^=]*)(.*)/echo -n \1 \|sed -r "s:[-.]:_:g"; echo -n \2/ge' file

```

same example:

```
kent$  echo "java.home=/usr/bin/java
groovy-home=/usr/lib/groovy
workspace.home=/build/me/my-workspace"|sed -r 's/([^=]*)(.*)/echo -n \1 \|sed -r "s:[-.]:_:g"; echo -n \2/ge'
java_home=/usr/bin/java
groovy_home=/usr/lib/groovy
workspace_home=/build/me/my-workspace

```
This might work for you (GNU sed):

```
sed -r 's/=/\n&/;h;y/-./__/;G;s/\n.*\n//' file

```

["You wait ages for a bus..."](https://stackoverflow.com/questions/14696606/substitute-characters-between-specific-strings)