bash: wget stdout 到 grep “word”如果不存在 grep "word2"打印字|字2

发布于 2024-12-13 12:31:24 字数 1926 浏览 2 评论 0 原文

我最近发现了一个名为 pwnedlist.com 的新网站,它跟踪受损的电子邮件帐户。

我认为尝试从列表中查询每封电子邮件对我来说是一个很好的练习。

我已经完成了所有这些,很好,但我的问题是我不知道一个好的方法 让标准输出通过两个 grep,而无需再次 wget'ing 第二个字符串。这是我到目前为止所拥有的......

    #!/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>

感谢任何帮助,谢谢!

I recently came across a new website called pwnedlist.com, it keeps track of compromised e-mail accounts.

I figured it would be a good practice exercise for me to try and query each email from a list.

I have all that done, fine and dandy, but my issue is that I don't know a good method for
have the stdout pass through both grep's without wget'ing a second time for the second string. Here's what I have so far....

    #!/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

This works like I want it to:

    $ ./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.

My issue is that I need to find a way to grep for the other parameter, the not-so-good one

   grep -i "we found"

is the string I need.

Here's the 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>

I tried this in hopes that it would print those "compromised" emails as well but it didn't work, my logic is incorrect.

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

Also, my choice of cut options looks kinda bulky/superfluous, any ideas for something cleaner? Using one command instead of sending it through cut a second time?

Here's the HTML:

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

Any help is appreciated, thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅蓝的眸勾画不出的柔情 2024-12-20 12:31:24

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

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

Why not use a grep that will check for both strings?

... grep -i "congratz\|we found" ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文