zoukankan      html  css  js  c++  java
  • shell文本处理

    1.文件整理
    employee文件中记录了工号和姓名
    employee.txt:
    100 Jason Smith
    200 John Doe
    300 Sanjay Gupta
    400 Ashok Sharma
    bonus文件中记录工号和工资
    bonus.txt:
    100 $5,000
    200 $500
    300 $3,000
    400 $1,250
    要求把两个文件合并并输出如下
    处理结果:
    400 ashok sharma $1,250
    100 jason smith  $5,000
    200 john doe  $500
    300 sanjay gupta  $3,000

    # awk 'ARGIND==1{test[$1]=$0}ARGIND==2{print test[$1],$2}' employee.txt bonus.txt 
    100 Jason Smith $5,000
    200 John Doe $500
    300 Sanjay Gupta $3,000
    400 Ashok Sharma  $1,250
    # cat employee.txt 
    100 Jason Smith
    200 John Doe
    300 Sanjay Gupta
    400 Ashok Sharma 
    # cat bonus.txt 
    100 $5,000
    200 $500
    300 $3,000
    400 $1,250 

    (2)查看swap分区的大小

    # free -m
                 total       used       free     shared    buffers     cached
    Mem:          1001        861        140         18         97        425
    -/+ buffers/cache:        338        663
    Swap:          509          0        509

    (3)root用户今天登陆了多长时间

    last查所有登陆信息,

    lastlog查看最近登陆,

    w或者who查看目前已经登陆用户

    (4)打印当前sshd的端口和进程id

    # netstat -anp | grep sshd

    (5)打印root可以使用可执行文件数

    # echo "root’s bins: $(find ./ -type f | xargs ls -l | sed '/-..x/p' | wc -l)"
    root’s bins: 53

    (6)输出本机创建20000个目录所用的时间

    # time for i in {1..2000} ; do mkdir neil$i; done
    
    real    0m2.086s
    user    0m0.180s
    sys    0m0.300s
    [berry@berry:dirs] time
    
    real    0m0.000s
    user    0m0.000s
    sys    0m0.000s
  • 相关阅读:
    Markdown语法
    Hello World
    sql笔试题-1
    解决高版本vm打开虚拟机报错
    zookeeper启动闪退
    java找出1~1000中素数的三种方式
    Java中更精确的计时
    vue系列之调试工具(vue-devtools)
    vue系列之npm命令错误
    vue系列之安装基础环境
  • 原文地址:https://www.cnblogs.com/Berryxiong/p/6291247.html
Copyright © 2011-2022 走看看