Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed extra characters at end of l command

Tags:

sed

freebsd

I am trying replace value in a config file with sed in cshell.

However it gives me the error:

sed: 1: "/usr/local/etc/raddb/mo ...": extra characters at the end of l command

I am trying the following command:

sed -i "s/private_key_password = .*/private_key_password = test/" /usr/local/etc/raddb/mods-available/eap

I have looked at examples of sed to do this but they all look similar with what I am doing, what is going wrong here?

like image 439
Gerard van den Bosch Avatar asked Feb 25 '16 06:02

Gerard van den Bosch


1 Answers

FreeBSD sed requires an argument after -i to rename the original file to. For example sed -i .orig 's/../../' file will rename he original file to file.orig, and save the modified file to file.

This is different from GNU sed, which doesn't require an argument for the -i flag. See sed(1) for the full documentation. This is one of those useful extensions to the POSIX spec which is unfortunately implemented inconsistently.

Right now, the "s/private_key_password = .*/private_key_password = test/" parts gets interpreted as an argument to -i, and /usr/local/etc/raddb/mods-available/eap gets interpreted as the command. Hence the error.

So you want to use:

sed -i .orig "s/private_key_password = .*/private_key_password = test/" /usr/local/etc/raddb/mods-available/eap

You can then check if the changes are okay with diff and remove /usr/local/etc/raddb/mods-available/eap.orig if they are.

like image 62
Martin Tournoij Avatar answered Nov 03 '22 09:11

Martin Tournoij