sed issue

Hi guys. Can somone advise as to what the problem is with the following sed command?

1) read -p "Please enter new username you wish to replace old: " new_username
        sed "s/$username/$new_username/" information_file
        ;;

This is one of the case statements included but I'm having trouble with this one. All I want it to do is replace any occurence of a given username in information_file.txt with a new username provided by user. My sed command either does nothing to it or just appends the new username on every line as well as next to the current username.

Many thanks!

P.S. $username has been prompted above the case statement so I doubt that's the problem :slight_smile:

There is nothing wrong with the sed command, apart that it seems you want to do a global substitution, to change all occurrences:

sed "s/$old/$new/g"

Double check your $username var; echo it out to make sure it is what you think it is.
Also, note that the changed content will be output to stdout, unless you redirect it into a new file or use -i switch to edit in-place (redirection is safer).