2011-11-02 48 views
0

我最近遇到一个名为pwnedlist.com的新网站,它跟踪受损的电子邮件帐户。bash:wget stdout grep“word”如果不存在grep“word2”打印word | word2

我想这将是一个很好的练习练习,以尝试查询列表中的每封电子邮件。

我已经完成了所有这些工作,但是我的问题是我不知道 有一个好的方法让stdout同时通过两个grep,而不用第二次为第二个字符串开始。这里是我到目前为止....

#!/usr/local/bin/bash 

    if [ -z "$1" ] 
    then 
      echo "Usage: $0 <list>" 
    exit 
    fi 

    for address in $(cat $1) 
    do 

    echo -n "$address  " 
    wget -O - --post-data "query_input=$address" pwnedlist.com/query 2>/dev/null | 
    grep -i congrats | cut -d '>' -f 2 | cut -d '<' -f 1 

    done 
    echo 

这就像我希望它:

$ ./querypwnlist testfile 
    [email protected]  Congrats! Your email is not in our list. 
    [email protected] Congrats! Your email is not in our list. 
    [email protected]   Congrats! Your email is not in our list. 

我的问题是,我需要找到一种方法来用grep为其他参数时,不太好的一个

grep -i "we found" 

是我需要的字符串。

这里的HTML:

<div id="query_result_negative" class='query_result_footer'>... we found your email/username in our database. It was last seen on 2011-08-30. Please read on.</div> 

我希望它会打印这些“不安全”的电子邮件,并尝试这样做,但它没有工作,我的逻辑是不正确。

wget ..... | (grep -i congrats || grep -i "we found") | cut .... 

而且,我选择的切选项看起来有点笨重/多余的,任何东西更清洁的想法?使用一个命令而不是通过第二次剪切发送?

这里的HTML:

<div id="query_result_negative" class='query_result_footer'>Congrats! Your email is not in our list.</div> 

任何帮助表示感谢,谢谢!

回答

2

为什么不使用grep来检查两个字符串?

... grep -i "congratz\|we found" ... 
+0

哇,我没有想到这一点,谢谢! – jonschipp