Select everything but a block of text
<p>I have a comprehensive host file for a distributed network monitoring system that I need split into two files. Some of the hosts go in one file and the rest go in the other. I'm using <code>sed</code> to pull the hosts I need out but I don't know how to put everything else in the other file, kind of like the <code>-v</code> option for <code>grep</code>.</p>

<p>Example of host file:</p>

<pre><code>object Host "router" {
  import "template"
  display_name = "router"
  address = "xx.xx.xx.xx "
}

object Host "switch" {
  import "template"
  display_name = "switch"
  address = "xx.xx.xx.xx "
}

object Host "router" {
  import "template"
  display_name = "router"
  address = "xx.xx.xx.xx "
}

object Host "otherthing" {
  import "template"
  display_name = "otherthing"
  address = "xx.xx.xx.xx "
}

object Host "switch" {
  import "template"
  display_name = "switch"
  address = "xx.xx.xx.xx "
}

object Host "otherthing" {
  import "template"
  display_name = "otherthing"
  address = "xx.xx.xx.xx "
}
</code></pre>

<p>The <code>sed</code> command I'm using to pull routers out</p>

<pre><code>sed '/router.*\n/p;//g;/{$/,/^}/H;//x;D' files/tmp/unsorted-host.tmp &gt;&gt; files/router.conf
</code></pre>

<p>Also I don't know if it would be more efficient to the sorting instead of building the large host file but here's how I make the large host file:</p>

<pre><code>    while read line
        do
                # The SNMP to check the device type outputs on multiple lines, check to ensure we only grab IP's
                getip=$(echo $line | awk '{print $1}')
                if ping -c 1 $getip &amp;&gt; /dev/null
                        then
                        ip=$getip
                        else
                        trash=$getip
                fi
                template="template"
                host_name=$(timeout -s KILL 2 /usr/bin/snmpwalk -v 2c -c community1 $ip 1.3.6.1.2.1.1.5.0 | awk '{print $NF}' )
                if [ -z "$host_name" ]
                        then
                        host_name=$(timeout -s KILL 2 /usr/bin/snmpwalk -v 2c -c community2 $ip 1.3.6.1.2.1.1.5.0 | awk '{print $NF}' )
                        if [ -z "$host_name" ]
                                then
                                host_name=$(timeout -s KILL 2 /usr/bin/snmpwalk -v 2c -c community3 $ip 1.3.6.1.2.1.1.5.0 | awk '{print $NF}' )
                                if [ -z "$host_name" ]
                                        then
                                        host_name=$(timeout -s KILL 2 /usr/bin/snmpwalk -v 2c -c community4 $ip 1.3.6.1.2.1.1.5.0 | awk '{print $NF}' )
                                        if [ -z "$host_name" ]
                                                then
                                                host_name=$(timeout -s KILL 2 /usr/bin/snmpwalk -v 2c -c community5 $ip 1.3.6.1.2.1.1.5.0 | awk '{print $NF}' )
                                                if [ -z "$host_name" ]
                                                        then
                                                        host_name=$(echo " Not found ")

                                                fi
                                        fi
                                fi
                        fi
                fi
                echo "
object Host $host_name {
  import \"$template\"
  display_name = $host_name
  address = \"$ip \"
}" 
        done &lt; files/tmp/hosts.tmp &gt; files/tmp/unsorted-hosts.tmp
</code></pre>

<p>The goal would be to have two files, one with routers and one with everything else. Thanks ahead of time for any and all advice!</p>