手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表2018年07月27日的文章

invalid command code ., despite escaping periods, using sed

 linux上面,如果替换文件中的内容,其实还是比较方便的。比如:sed -i 's/xxx/yyy/g' xxx.txt

然而同样的命令,如果放到mac下面,就会报:sed: 1: "xxx.txt": invalid command code o
到stackoverflow.com就会发现已经有人回复了:https://stackoverflow.com/questions/19456518/invalid-command-code-despite-escaping-periods-using-sed
XML/HTML代码
  1. 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.  
  2.   
  3. Try adding the -e argument explicitly and giving '' as argument to -i:  
  4.   
  5. find ./ -type f -exec sed -i '' -e "s/192.168.20.1/new.domain.com/" {} \;  
  6. See this.  
所以上面的代码就改为:sed -i '' -e 's/xxx/yyy/g' xxx.txt ,搞定
 
参考:
1、https://stackoverflow.com/questions/19456518/invalid-command-code-despite-escaping-periods-using-sed
2、https://stackoverflow.com/questions/7573368/in-place-edits-with-sed-on-os-x
 
 
 

Tags: sed