I have a file using the following format:

```
M104 S200
M107
M104 S250
M110
M104 S275

```

I'm trying to find a way to match let's say the second occurrence of `M104` and rewrite the entire line to something else ALSO containing `M104`.

I've tried

```
sed 's/^M104/s/.*/M104 S300/' file - but it replaces all instances of M104
sed '0,/M104/s//M104 S200/' file - leaves the trailing text on the line

```

* a few other variations that are giving me unexpected results. Any help? ;)