I have a file that contains users. The format of the file is as follows:

```
groupname:
username \
username2 \
username3 \

```

and so on.

I am automating a portion of adding users to this file. I am currently using sed to complete this, but I am running into an issue. Here is what I am using for my sed command

```
sed -i '/groupname/ a\'newuser' \ \' /path/to/file

```

My problem is that the above command will enter a space after the backslash, which, for unknown reasons causes the application that utilizes this file to cease working.

I tried using the following with no positive results

```
sed -i '/groupname/ a\'newuser' \\' /path/to/file
sed -i '/groupname/ a\'newuser \'\ /path/to/file
sed -i '/groupname/ a\"newuser \"\ /path/to/file
sed -i '/groupname/ a\'newuser' "\"\ /path/to/file

```

My next step I think might be ritual sacrifice, but, I would prefer not to have to go that route.

I did try one thing with awk, but, I am less familiar with that.

```
awk '{print} /groupname/{print "newuser \"}' /path/to/file

```

That is met with an error message about an unterminated string starting at the " for "testing

Any suggestions would be met with much enthusiasm until such a point ritual sacrifice might actually become a reality, then its just sad faces all around.

Thanks in advance.

[edit]

For clarification, this command is being run from another server via ssh. So the command that executes from server A is as follows:

```
ssh serverb "sudo sed -i '/groupname/ a\'newuser' \ \" /path/to/file

```

That command works to the extent it inserts the extra space after the "\" which I don't need.