Hi Lush!
I sure hope you've found an answer to this by now, but I think I see the problem. In your 'sed' command, the search string you're using is 'user2: *'. What this matches is 'user2:' followed by any number of spaces. Using your example, the result is that it ADDS 'root' in before the existing data:
Code:
$ cat > test.txt
username1: aaaa
user2: bbbb2
useradmin3: ccccd
$ sed 's/user2: */user2: root/' test.txt
username1: aaaa
user2: rootbbbb2
useradmin3: ccccd
So, if what you really want to do is replace that entire line, you have to use the "." wildcard. The dot means "Any Single Character". The asterisk doesn't behave like you'd expect it to in regular expressions. It means that the character before it can repeat until infinity and it'll keep matching it.
So in your example, you're matching an infinite number of "spaces" with " *". To match ANY character, not just spaces, you'll want to use the dot.
Code:
$ sed 's/user2: .*/user2: root/' test.txt
username1: aaaa
user2: root
useradmin3: ccccd
That should give you the result you're looking for. I hope this helps!
-Jeo