【发布时间】:2010-09-25 22:09:30
【问题描述】:
我需要使用 grep 查找具有一堆名称的行,例如来自 file.txt 的 clientLogin=a@yahoo.com、clientLogin=b@gmail.com。
file.txt 有垃圾邮件,即email=a@yahoo.com email=b@gmail.com。我需要过滤掉这些
一旦我得到这些行,我需要 grep 获取 gmail 和 yahoo 并计算它们的数量
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 ]
这不起作用。如何动态替换 $l.get(1) 值?
问题是 ${l.get(0)} 必须在 " " 内, 即:
def gmail = ['sh','-c','grep "clientLogin=${l.get(0)}" file.txt' | grep gmail | wc -l ]
所以它看起来像:
def gmail = ['sh','-c','grep "clientLogin=a@yahoo.com" file.txt' | grep gmail | wc -l ]
但clientLogin=${l.get(0)} 不会产生结果。我不确定我哪里出错了。
感谢您的建议,但至少在我尝试时不会产生结果。
file.txt 有很多垃圾和类似的模式:
Into the domain clientLogin=a@yahoo.com exit on 12/01/2008 etc..
所以我愿意
def ex = ['sh','-c','grep "domain clientLogin=$client" file.txt'| grep "something more" | wc -l]
这样我就可以根据需要链接 grep 并最终达到我需要的计数。
如果我使用,我不确定是否可以链接 greps
def ex = ['grep', "$client", 'file.txt']
感谢您的意见。
【问题讨论】: