0

I'm using sed to modify a file. In simple terms, my modifier looks as so

sed -e '11s/$/ $LinuxUsername/'

This is suppose to add in their linux username at the end of line 11, however, it is instead posting the actual variable name "$LinuxUsername" at the end of line 11. How can i make it post the actual value of the variable?

I've tried using quotes and double quotes in different parts of the expression, but still failed to get it to work properly.

Currently, line 11 is looking like the following...

  john.doe william.mcmillion jonny.doeboy $LinuxUsername $LinuxUsername

Edit

The following is correct. Error was found further upstream.

sed -e "11s/$/ $LinuxUsername/"
TrevorKS
  • 638
  • 1
  • 1
    http://mywiki.wooledge.org/Quotes and https://unix.stackexchange.com/q/400447/170373 (I can't believe I can't find a more appropriate duplicate question) – ilkkachu Jun 20 '18 at 14:00
  • 1
    Linking in: https://unix.stackexchange.com/q/400447/117549 – Jeff Schaller Jun 20 '18 at 14:01
  • sed -e '11s/$/ $LinuxUsername/' sed -e "11s/$/ $LinuxUsername/" sed -e "11s/$/ $LinuxUsername/" All yield the same results, am i misunderstanding this? – TrevorKS Jun 20 '18 at 14:04
  • 1
    That 2nd one should have put the contents of that variable at the end of the line. Is the variable populated? – Jeff Schaller Jun 20 '18 at 14:14
  • Notice that when you asked https://unix.stackexchange.com/q/450647/117549, you didn't say that the username was a variable, so while you got an answer, you didn't get the answer to your real problem. – Jeff Schaller Jun 20 '18 at 14:15
  • The 2nd one is correct, it seems the error was the populated variable as you have mentioned, it was getting replaced with its own name further upstream in the code.

    Thanks you for the help, sorry for the unneeded question.

    – TrevorKS Jun 20 '18 at 14:22

0 Answers0