sed extra characters at end of l command

扶醉桌前 提交于 2019-12-07 06:04:23

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/35620009/sed-extra-characters-at-end-of-l-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!