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
  • 相关阅读:
    查看Linux系统版本和内核信息
    XManager连接CentOS6.5
    Linux系统中Ant的安装与实例应用
    Linux常用命令列表
    虚拟机中CentOS系统添加新磁盘
    Linux-IP网络设置
    [原创]Toolbar setNavigationIcon无效
    [转]JAVA回调机制(CallBack)详解
    [原创]PM2使nodejs应用随系统启动
    [原创]Linux(CentOS)下安装mongodb
  • 原文地址:https://www.cnblogs.com/Berryxiong/p/6291247.html
Copyright © 2011-2022 走看看