zoukankan      html  css  js  c++  java
  • awk

    [root@mhc regular]# last -n 2|awk '{print $1 " " $3}'
    root    :0
    root    :0
        
    wtmp    Wed

    [root@mhc regular]# last -n 2|awk '{print $1 " lines:" NR " columes:" NF}'
    root    lines:1     columes:10
    root    lines:2     columes:10
        lines:3     columes:0
    wtmp    lines:4     columes:7

    [root@mhc regular]# cat /etc/passwd | awk '{FS=":"} $3 < 10 {print $1 " " $3}'
    root:x:0:0:root:/root:/bin/bash    
    bin    1
    daemon    2
    adm    3
    lp    4
    sync    5
    shutdown    6
    halt    7
    mail    8

    [root@mhc regular]# cat /etc/passwd | awk '{FS=":"} NR==2 {print $1 " " $3}'
    bin    1

    [root@mhc regular]# cat /etc/passwd | awk 'BEGIN {FS=":"} $3 < 10 {print $1 " " $3}'
    root    0
    bin    1
    daemon    2
    adm    3
    lp    4
    sync    5
    shutdown    6
    halt    7
    mail    8

    [root@mhc regular]# cat pay.txt
    Name    1st    2nd
    aa    200    300
    bb    250    550

    [root@mhc regular]# cat pay.txt | awk 'NR==1{printf "%10s %10s %10s %10s ", $1, $2, $3, "Total"} NR>=2{total = $2 + $3
    > printf "%10s %10d %10d %10.2f ", $1, $2, $3, total}'
          Name        1st        2nd      Total
            aa        200        300     500.00
            bb        250        550     800.00

    [root@mhc regular]# cat a.sh
    #!/bin/bash

    cat pay.txt | awk 'NR==1{printf "%10s %10s %10s %10s ", $1, $2, $3, "Total"} NR>=2{total = $2 + $3
    printf "%10s %10d %10d %10.2f ", $1, $2, $3, total}'
    [root@mhc regular]#
    [root@mhc regular]#
    [root@mhc regular]# ./a.sh
          Name        1st        2nd      Total
            aa        200        300     500.00
            bb        250        550     800.00

  • 相关阅读:
    测试SQL
    UpdatePanel中弹出新窗口
    无法打开物理文件 操作系统错误 5:拒绝访问 SQL Sever
    Repeater嵌套Repeater
    SQL2000清除SQL日志
    sql批量修改字段内容的语句-SQL技巧
    SQL时间格式化 转载备用~
    远程连接数据库
    MySql 文件导入导出
    pyspark启动与简单使用----本地模式(local)----shell
  • 原文地址:https://www.cnblogs.com/mhc-fly/p/8318528.html
Copyright © 2011-2022 走看看