zoukankan      html  css  js  c++  java
  • 一些简单的shell脚本实例

    1.词频统计

     sed -e s/'[[:punct:]]'/' '/g -e s/'[[:digit:]]'/' '/g $filename| tr [A-Z] [a-z] | tr ' ' ' '| tr ' ' ' ' | sed '/^$/d' >>newfilename

    #干掉文本中的标点和数字

    #替换大小写

    #替换换行符为空格后再替换空格为换行符(可能不必要)

    #删除空行重定向到新文件

    sort newfilename| uniq -c | sort -n

    #排序后删除重复项并统计重复个数,然后重新排序。sort -n的作用是按照数值进行排序。

    统计部分也可以用awk来搞:sed -e s/'[[:punct:]]'/' '/g -e s/'[[:digit:]]'/' '/g $filename| tr [A-Z] [a-z] | tr ' ' ' '|awk 'BEGIN{RS=" "} {++w[$0]} END{for(a in w) if(a!="") print a": "w[a]}'|sort -k2 -n

    输出结果都差不多。

    2.用ping看本网段在线的ip地址。

    for i in `seq 2 255`

    do

    ping -c 1 "192.168.1.$i"|grep "1 received " && echo "192.168.1.$i"

    done

    3.简单的系统监控脚本

    #!/bin/sh
    CONTINUE(){

    read -p "press enter to continue:"

    }

    CPU_INFO(){

    echo "print the cpu info:"

    cat /proc/cpuinfo|awk 'BEGIN{FS=":"}/model name/{print "CPU model:"$2}'|uniq

    cat /proc/cpuinfo|awk 'BEGIN{FS=":"}/cpu MHz/{print "CPU MHz:"$2"MHz"}'|uniq

    }

    LOAD_INFO(){

    echo

    echo "print the system load info:"

    uptime|awk 'BEGIN{FS=":"}{print $5}'|awk 'BEGIN{FS=","}{print "last 1 minute sys load:"$1" last 5 minutes sys load"$2" last 15minutues sysload:"$3" "}'

     }

    MEM_INFO(){

    echo

    echo "print the system memory and swap info:"

    free -h |grep Mem|awk 'BEGIN{FS=" "}{print "system free memory info:"$4""}'

    free -h |grep Swap|awk 'BEGIN{FS=" "}{print "system swap info:"$4""}'

    }

    DISK_INFO(){

    echo

    echo "print the system disk info:"
    df -h

    echo

    }

    MAIN(){
    clear

    echo "============================================"

    echo "1.display the cpu info;"
    echo "2.display the sys load;"
    echo "3.display MEM and swap info;"
    echo "4.display the sys disk info;"
    echo "5.EXIT;"

    echo "============================================"

    read -p "please select an iterm(1-5):" SELECT

    CHOICE
    }

    CHOICE(){
    case $SELECT in
    1)
    CPU_INFO
    CONTINUE

    MAIN

    ;;

    2)
    LOAD_INFO
    CONTINUE
    MAIN

    ;;

    3)
    MEM_INFO
    CONTINUE
    MAIN
    ;;

    4)

    DISK_INFO
    CONTINUE
    MAIN
    ;;

    5)
    exit
    ;;

    *)
    CONTINUE
    MAIN
    ;;
    esac

    }

    MAIN

  • 相关阅读:
    Node.js :HTTP请求和响应流程
    Node.js :URL、QueryString介绍
    jQuery
    如何angular过滤器进行排序???
    封装jsonp
    原生js的math对象
    Iscrool下拉刷新
    javascript闭包
    javascript对象(3)
    javascript对象(2)
  • 原文地址:https://www.cnblogs.com/axeprpr/p/4841749.html
Copyright © 2011-2022 走看看