doulong6761 2017-08-01 14:42
浏览 149

php脚本上的sed bash命令

I need to delete some lines from my dhcpd.conf file by a simple php script. So I'm trying to use sed command to do that. On terminal I've tryed to use this command to delete from line 1 to 3 and it works:

sed -i '1,3d' pippo.txt

The problem is that i can't understand how to use sed passing some php variable for line numers. I need something like:

sed -i '$var1,$var2d' pippo.txt

can someone help me with the correct sintax for that command on php pls. Thanks.

  • 写回答

1条回答

  • douxiezha9319 2017-08-01 14:47
    关注

    Just use double quotes to expand the variables and wrap the variables with curly braces.

    var1=1
    var2=2
    sed -i "${var1},${var2}d" pippo.txt
    

    You can define a variable as $var2d. If you need to use the variable $var2, followed by letter d, then you must use curly braces as in ${var2}d. However this is not necessary for $var1 in this case as there is no ambiguity, but it's good to follow as a practice.

    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办