-1

I have the next bock of code in Vagrantfile:

  node.vm.network 'private_network',
    ip: ip_prefix + "#{index}",
    nic_type: "virtio"

  if additional_ifaces
    additional_ifaces.each do |iface|
      node.vm.network 'private_network',
        ip: iface['ip'],
        nic_type: "virtio"
    end
  end

I want to remove this block of code with the help of sed. Could you please help? P.S.: I don't want to use a range of line numbers for removal as long as content of file is being changed frequently.

I was trying to achieve it by using variable and pass it to sed, however it raises error about escaping:

$ sed -i "s/$l//g" Vagrantfile 
sed: -e expression #1, char 38: unterminated `s' command

The content of variable is:

$ echo $l
node.vm.network \'private_network\', ip: ip_prefix \+ "\#\{index\}", nic_type: virtio \if additional_ifaces additional_ifaces\.each \do \|iface\| node\.vm\.network \'private_network\'\, \ip: iface\[\'ip\'\], nic_type: "virtio" end end
user54
  • 413
  • 2
  • 5
  • 19
  • The goal is that you add some code of your own to show at least the research effort you made to solve this yourself. [Stack Overflow is a question and answer site for professional and enthusiast programmers](http://stackoverflow.com/tour). – Cyrus Sep 30 '17 at 13:35

2 Answers2

1

I suggest with GNU sed:

sed '/^  node\.vm\.network .private_network.,$/,/^  end$/d' file

If you want to edit your file "in place" use sed's option -i.


See: The Stack Overflow Regular Expressions FAQ

Cyrus
  • 69,405
  • 13
  • 65
  • 117
1

You can remove the specific no of lines after pattern match using below

sed -i -e '/node.vm.network/,+10d' Vagrantfile