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

  • 相关阅读:
    6、scala面向对象-对象
    C# App.config配置文件的讲解
    abstract、override、new、virtual、sealed使用和示例
    C# 枚举的使用
    深入浅出面向对象分析与设计
    数据契约(DataContract)的作用
    C# 启动停止SQLServer数据库服务器
    C# 定时器计划任务
    C# 程序只能执行一次
    WPF dataGrid中的check的改变事件
  • 原文地址:https://www.cnblogs.com/mhc-fly/p/8318528.html
Copyright © 2011-2022 走看看