Question: So I have the following file:

```
Carlton 3053
Carlton North 3054
Docklands 3008
East Melbourne 3002
Flemington 3031
Kensington 3031
Melbourne 3000
Melbourne 3004
North Melbourne 3051
St Kilda East 3183

```

I want to replace the last space just before the numbers with a hyphen, this is the closest I've got

```
cat file.txt | sed -r 's/\ /\-/g'

```

But this replaces all spaces with a -
I want the output to look like this:

```
Carlton-3053
Carlton North-3054
Docklands-3008
East Melbourne-3002
Flemington-3031
Kensington-3031
Melbourne-3000
Melbourne-3004
North Melbourne-3051
St Kilda East-3183

```

Any ideas?

Answer: 
You know how to replace the first space, right?

```
rev inputfile | sed 's/ /-/' | rev

```
The following also works on OSX since `sed -r` is not available there:

```
sed 's/\(.*\) /\1-/' file_containing_your_text.txt

```