sed reports "unknown command"

I wrote this:

sudo sed -i ‘s/3389/3390/g’ /etc/xrdp/xrdp.ini

That produced this error:

sed: -e expression #1, char 1: unknown command: `'
0

2 Answers

Compare your

 sudo sed -i ‘s/3389/3390/g’ /etc/xrdp/xrdp.ini

vs the correct

 sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.ini

Check the different type of quotes.

Be careful when copy-pasting from document editors like Writer or Word, those will often automatically change quotes (and other things) to match your locals.

1

I had the same error but the cause was different. I did not use the ` character, nor did I copy-paste the code from somewhere. I was writing a sed script with a condition, and used a new line for the command. Posting this here in case someone else has the same problem and wasn't helped by the accepted answer.

Here is how to replicate the error:

echo class:myclass > myfile
cat script
/class:/
s/myclass/MYCLASS/g #ctrl+d to exit
sed -f script myfile

Output:

sed: file script line 2: unknown command: `
'

What fixes it is either to place the command after the condition (on the same line), or use curly braces, so that the script looks like this:

/class:/ s/myclass/MYCLASS/

Or this:

/class:/ {
s/myclass/MYCLASS/
}

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like