Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Quick suggestions:</p> <ol> <li><p>Avoid the <a href="http://partmaps.org/era/unix/award.html" rel="nofollow noreferrer">useless use of <code>cat</code></a> and change <code>cat X | grep Y</code> to <code>grep Y X</code>.</p></li> <li><p>You can process the <code>grep</code> output as it is produced by piping it rather than using backticks. Using backticks requires the first <code>grep</code> to complete before you can start the second <code>grep</code>.</p></li> </ol> <p>Thus:</p> <pre><code>grep -i -o -E "[A-Z0-9.-]+@[A-Z0-9.-]+" "$1" | while read line; do grep -m 1 "\b$line\b" "$2" done </code></pre> <p>Next step:</p> <ol> <li>Don't process <code>$2</code> repeatedly. It's huge. You can save up all your patterns and then execute a single grep over the file.</li> <li>Replace loop with <code>sed</code>.</li> </ol> <p>No more repeated <code>grep</code>:</p> <pre><code>grep -i -o -E "[A-Z0-9.-]+@[A-Z0-9.-]+" "$1" | sed -E 's/^|$/\\1/g' &gt; patterns grep -f patterns "$2" </code></pre> <p>Finally, using some <code>bash</code> fanciness (see <code>man bash</code> &rarr; Process Substitution) we can ditch the temporary file and do this in one long line:</p> <pre><code>grep -f &lt;(grep -i -o -E "[A-Z0-9.-]+@[A-Z0-9.-]+" "$1" | sed -E 's/^|$/\\b/g') "$2" </code></pre> <hr> <p>That's great unless you have so many patterns <code>grep -f</code> runs out of memory and barfs. If that happens you'll need to run it in batches. Annoying, but doable:</p> <pre><code>grep -i -o -E "[A-Z0-9.-]+@[A-Z0-9.-]+" "$1" | sed -E 's/^|$/\\1/g' &gt; patterns while [ -s patterns ]; do grep -f &lt;(head -n 100 patterns) "$2" sed -e '1,100d' -i patterns done </code></pre> <p>That'll process 100 patterns at a time. The more it can do at once the fewer passes it'll have to make over your 2nd file.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload