Search code examples
bashshellunixsedbin

Bash sed -i update with trailing backslash


i want to run this :

sed -i -e "s/\($user hard nproc \).*/\1{value here ending with /}/" /etc/something.conf

here, {value here ending with /} is like 100/ or abc/

however if i just put / like :

sed -i -e "s/\($user hard nproc \).*/\1abc//" /etc/something.conf

i get this error : unknown option to `s'

I have been tring to fix this but can't think of any solution...

Basically what i am trying to do is update my old value from "username hard nproc 10" to "username hard nproc 10**" with the "**".


Solution

  • You need to either escape the trailing slash or use a different character for the expression. i.e.:

    sed -i "s/\($user hard nproc \).*/\1abc\//" /etc/cgrules.conf
    

    or

    sed -i "s#\($user hard nproc \).*#\1abc/#" /etc/cgrules.conf