本文介绍了在 OS X 上将“sed"与“find"命令一起使用时出错:“无效命令代码".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

被迫对当前客户端使用 CVS,并且远程存储库的地址已更改.我能找到在本地代码中更改远程地址的唯一方法是递归搜索和替换.

Being forced to use CVS for a current client and the address changed for the remote repo. The only way I can find to change the remote address in my local code is a recursive search and replace.

但是,我希望使用 sed 命令:

However, with the sed command I'd expect to work:

find ./ -type f -exec sed -i "s/192.168.20.1/new.domain.com/" {} ;

我收到每个文件的错误:

I get an error for every file:

sed: 1: ".//file/path ...": invalid command code .

我试图逃避 sed 匹配/替换中的句点,但这并不能解决任何问题.

I've tried to escape the periods in the sed match/replacement but that doesn't solve anything.

推荐答案

如果您使用的是 OS X,这可能与 sed 命令无关.在 sed 的 OSX 版本上,-i 选项需要一个 extension 参数,因此您的命令实际上被解析为 extension 参数,文件路径被解释为命令代码.

If you are on a OS X, this probably has nothing to do with the sed command. On the OSX version of sed, the -i option expects an extension argument so your command is actually parsed as the extension argument and the file path is interpreted as the command code.

尝试显式添加 -e 参数并将 '' 作为参数提供给 -i:

Try adding the -e argument explicitly and giving '' as argument to -i:

find ./ -type f -exec sed -i '' -e "s/192.168.20.1/new.domain.com/" {} ;

请参阅.

这篇关于在 OS X 上将“sed"与“find"命令一起使用时出错:“无效命令代码".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 07:05