关于mac OSX下的sed

mac OS X下的sed出错

      其实这里只是记录一下自己在用sed修改文件的时候遇到的现象。

      网上有很多sed的讲解,还算详细。今天打算改一些网页,打算加一句代码,于是有了如下的语句:

sed -i "s/class=\"look\"/class=\"look\" id=\"lookBigView\"/g" *

      然而报错:

sed: -i may not be used with stdin

      = 。=|||
      我觉得自己循规蹈矩,按照步骤一点点来的,什么叫不能用标准输入……我没有用啊!!!然后利用国内某知名搜索引擎一下午……无解……面对这样的脚本问题,一句话的事情,作为一名有志气的程序员,怎能咽得下这口气!于是转战Google,好吧,瞬间把我拽到的Stackoverflow(原问题点我

The problem is that Mac OS X uses the BSD version of sed, which treats the -i option slightly differently. The GNU version used in Linux takes an optional argument with -i: if present, sed makes a backup file whose name consists of the input file plus the argument. Without an argument, sed simply modifies the input file without saving a backup of the original.

In BSD sed, the argument to -i is required. To avoid making a backup, you need to provide a zero-length argument, e.g. sed -i ” y.tab.c ….

Your command, which simply edits y.tab.c with no backup in Linux, would attempt to save a backup file using ‘y.tab.c’ as an extension. But now, with no other file in the command line, sed thinks you want to edit standard input in-place, something that is not allowed.

      终于明白不是我的错了(T 0 T)…Mac OS X是BSD的孩子,那么就跟着父亲来,sed -i 之后需要加参数,表示备份原文件……

      于是,代码如下即可:

sed -i "" "s/class=\"look\"/class=\"look\" id=\"lookBigView\"/g" *
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值