Grep one file and remove contents of the grep with sed -i on a second file <p>I am trying to grep ip addresses from one file and remove the contents of the grep from a second file with a single command.</p> <p>The masterfile has</p> <pre><code>header x.x.x.x header x.x.x.x header2 y.y.y.y header2 y.y.y.y header3 z.z.z.z header3 z.z.z.z </code></pre> <p>The tempfile has</p> <pre><code>x.x.x.x x.x.x.x y.y.y.y y.y.y.y z.z.z.z z.z.z.z </code></pre> <p>Attempt</p> <pre><code>grep "header" masterfile | sed 's/^.* //' | sed -i "" '/$/d' tempfile </code></pre> <p>Would also like to remove the empty line after the sed command removes an entry.</p>