ºìÁªLinuxÃÅ»§
Linux°ïÖú

Ç°¶Îʱ¼ä²Î¼ÓÌÔ±¦ÍøÕÐƸ¶þÃæµÄshell½Å±¾µÄÌâÄ¿

·¢²¼Ê±¼ä:2009-01-10 12:28:46À´Ô´:ºìÁª×÷Õß:bitspirit
Ç°¶Îʱ¼äÔÚ¹þ¹¤´ó²Î¼ÓÌÔ±¦ÍøµÄÕÐƸ£¬¶þÃæµÄʱºòÃæÊÔ¹Ù¸øÎÒ³öÁËÒ»µ½shell½Å±¾µÄÌâÄ¿£¬ÈçÏ£º
Ò»¸öÎı¾ÀàÐ͵ÄÎļþ£¬ÀïÃæÿÐдæ·ÅÒ»¸öµÇ½ÕßµÄIP£¨Ä³Ð©ÐÐÊÇÖظ´µÄ£©£¬Ð´Ò»¸öshell½Å±¾Êä³öµÇ½´ÎÊý×î¶àµÄÓû§¡£

PS£ºµ±Ê±Ã»ÓÐ×ö³öÀ´£¬Ç°¶Îʱ¼äÎÒÔÙ´Îѧϰshell½Å±¾µÄʱºòÏëµ½ÁËÒ»ÖÖ·½·¨¿ÉÒÔÇó½â£¬µ«ÊǸоõÓеãÂé·³¡£ÔÚÕâÀïÇë½Ì£¬¸÷λ¶ÔÓÚÕâµÀÌâÄ¿ÓÐʲôºÃµÄ½â·¨£¿
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 7 ÌõÆÀÂÛ

  1. tkfly0324 ÓÚ 2009-02-27 14:43:21·¢±í:

    ûÓÐÌâÁË

  2. gondn125 ÓÚ 2009-02-25 15:23:25·¢±í:

    ÌⶼûÁË

  3. karon_fedora ÓÚ 2009-02-03 14:07:06·¢±í:

    ÒýÓÃ:
    Ô­ÌûÓÉ jiangking ÓÚ 2009-2-3 11:29 ·¢±í
    cat in_put | uniq -c | sort | tail -1 | awk '{print $2}'²»¾­¹ýÅÅÐòÊDz»Ðеģ¬Êä³ö½á¹û´íÎó
    cat in_put | sort|uniq -c | sort | tail -1 | awk '{print $2}'¼´¿É

    ¶÷ ¶÷
    ÎÒûÓÐʵÑé,Ö±½ÓдµÄ..>_<

  4. jiangking ÓÚ 2009-02-03 11:29:12·¢±í:

    cat in_put | uniq -c | sort | tail -1 | awk '{print $2}'²»¾­¹ýÅÅÐòÊDz»Ðеģ¬Êä³ö½á¹û´íÎó
    cat in_put | sort|uniq -c | sort | tail -1 | awk '{print $2}'¼´¿É

  5. karon_fedora ÓÚ 2009-02-02 16:37:14·¢±í:

    cat in_put | uniq -c | sort | tail -1 | awk '{print $2}'

  6. ailyanlu ÓÚ 2009-02-01 00:08:00·¢±í:

    ÓÃawk '{printf $2}'¾Í¿ÉÒÔÁË~

  7. bitspirit ÓÚ 2009-01-10 20:45:47·¢±í:

    ÒÔÏÂÊÇÎÒ×Ô¼ºÏëµÄ½â·¨£¬¸Ð¾õ²»ÍêÃÀ£¬ÄóöÀ´´ó¼Ò¸øÇÆÇÆ£¬Íû¶àÌáһЩÒâ¼û£¡
    ¼ÙÉèÎļþÖеÄIPÊÇÕâÑùµÄ£¬ip_input:
    219.217.49.14
    175.43.4.87
    87.48.98.1
    59.73.38.25
    219.217.50.14
    59.92.48.32
    219.217.49.14
    59.72.38.142
    59.73.38.25
    219.217.49.14

    ÎÒÃÇÕâÀïÒ»²½Ò»²½À´
    1£¬ sort ip_input
    Ê×ÏÈʹÓÃsortÃüÁîÅÅÐò£¬ÕâÑùÏàͬµÄIPµØÖ·Ôò¿ÉÒÔÅÅÔÚÒ»Æð£¬Õâ²½ÎÒÊÇΪÁ˽ÓÏÂÀ´Ê¹ÓÃÃüÁîuniq¡£ÒòΪuniqÃüÁîÒªÇóÊÇʹÏàÁÚµÄÐÐΨһ£¬Èç¹ûÏàͬÐÐÖ®¼ä´æÔÚÆäËüÐÅÏ¢£¬ÃüÁî²»»áʹ½á¹û¡°Î¨Ò»¡±£¡
    Êä³ö½á¹ûΪ£º
    175.43.4.87
    219.217.49.14
    219.217.49.14
    219.217.49.14
    219.217.50.14
    59.72.38.142
    59.73.38.25
    59.73.38.25
    59.92.48.32
    87.48.98.1

    2£¬ sort ip_input | uniq -c
    ÕâÀï½âÊÍÒ»ÏÂuniq -c Ñ¡Ïî¡£ËüµÄ×÷ÓÃÊǽ«Öظ´ÐÐÈ¥µô²¢ÇÒÔÚÿÐеÄÇ°ÃæÌí¼Ó´ËÐÐÖظ´µÄ´ÎÊý£¬ÏÂÒ»²½Ôò¶Ô´Ë½á¹û½øÐÐÅÅÐòÔò¿ÉÒÔÕÒµ½µÇ¼´ÎÊý×î¶àµÄIP¼Ç¼ÒÔ¼°µÇ¼´ÎÊý¡£
    Êä³ö½á¹ûΪ£º
    1 175.43.4.87
    3 219.217.49.14
    1 219.217.50.14
    1 59.72.38.142
    2 59.73.38.25
    1 59.92.48.32
    1 87.48.98.1
    £¨ÔÚµÚÒ»¸ö³öÏÖ´ÎÊý֮ǰ»áÓкܶà¿Õ¸ñ£¬ÕâÊÇÔõô»ØÊÂÄØ¡£¡£¡££©

    3£¬ sort ip_input | uniq -c | sort -r > tmp
    sortÃüÁîµÄĬÈÏÅÅÐò·½Ê½ÊÇÉýÐò£¬Ê¹Óà -r Ñ¡ÏîÄæÐòÅÅÐò½á¹û£¬Ôò³öÏÖ´ÎÊý×î¶àµÄIPÔòÅÅÔÚÁ˵ÚÒ»ÐУ¬²¢½«½á¹û±£´æÔÚtmpÎļþµ±ÖС£

    4£¬ sed -n '1p' tmp && rm -f tmp
    ÕâÀïµÄsed -n ÓÃÓÚ½«ÎļþtmpµÄµÚÒ»ÐÐ×öÎöÈ¡²Ù×÷£¬´ËʱÊä³ö½á¹ûΪ£º
    3 219.217.49.14
    IP 219.217.49.14 ³öÏֵĴÎÊý×î¶à£¬Îª 3 ´Î¡£


    PS£ºÔÚ½á¹ûÖУ¬µÚÒ»¸öÊý×ÖΪ´ËIP¼Ç¼ÔÚÎļþµ±ÖгöÏֵĴÎÊý£¬ÕâÀïÎÒ±¾²»Ï뽫3Êä³ö£¬²»¹ýÎÒûÓÐÌ«ºÃµÄ°ì·¨½â¾ö¡£µ±È»°ì·¨Ò²ÊÇÓеģ¬²»¹ý¸Ð¾õºÜ±¿×¾¡£Ï£Íû¸÷λ¶àÌáһЩºÃµÄ½â¾ö·½°¸£¡£¡£¡