Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use a variable in a grep with groovy?
    primarykey
    data
    text
    <p>I need to grep for lines with bunch of names, say <code>clientLogin=a@yahoo.com</code>, <code>clientLogin=b@gmail.com</code> from a file.txt.</p> <p>file.txt has junk which is <code>email=a@yahoo.com email=b@gmail.com</code>. I need to filter these out</p> <p>Once I get these lines I need to grep for gmail and yahoo and get their counts</p> <pre><code>List l = new ArrayList{a@yahoo.com, b@gmail.com} def gmail = ['sh','-c','grep "clientLogin="$l.get(0) file.txt' | grep gmail | wc -l ] def yahoo = ['sh','-c','grep "clientLogin="$l.get(1) file.txt' | grep yahoo| wc -l ] </code></pre> <p>This doesn't work. How can I substitute the $l.get(1) value dynamically?</p> <hr> <p>the problem is that ${l.get(0)} has to be inside the " ", i.e.:</p> <pre><code>def gmail = ['sh','-c','grep "clientLogin=${l.get(0)}" file.txt' | grep gmail | wc -l ] </code></pre> <p>so that it will look like:</p> <pre><code>def gmail = ['sh','-c','grep "clientLogin=a@yahoo.com" file.txt' | grep gmail | wc -l ] </code></pre> <p>but <code>clientLogin=${l.get(0)}</code> doesn't produce the result. I am not sure where I am going wrong. </p> <p>Thanks for your suggestion but it doesn't produce the result, at least when I tried it.</p> <hr> <p>file.txt has lot of junk and a pattern something like:</p> <pre><code>Into the domain clientLogin=a@yahoo.com exit on 12/01/2008 etc.. </code></pre> <p>hence I do </p> <pre><code>def ex = ['sh','-c','grep "domain clientLogin=$client" file.txt'| grep "something more" | wc -l] </code></pre> <p>that way I can chain the grep as I want and eventually land at the count I need.</p> <p>I am not sure if I can chain the greps if I use </p> <pre><code>def ex = ['grep', "$client", 'file.txt'] </code></pre> <p>thanks for your input.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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