zoukankan      html  css  js  c++  java
  • Bash awk 基本入门

    Bash awk 基本入门

    Awk ‘patten {action}’ file

    Akw command is used to handle fields in one line.

    Analize every line in the file, and if the line match the patten, then do the action.

    pattern field is optional.

    $0 indicates the whole line.

    The first field is $1.

    [braveyly@m-net ~]$ cat awk.txt

    liwei  27  male     hust

    lijing 24  femaile  cnnu

    hujuan 22  female   cnnu

    hurui  18  male     hust

    [braveyly@m-net ~]$ awk '$2 > 23 {print $1, $3, $4}' ./awk.txt

    liwei male hust

    lijing femaile cnnu

    [braveyly@m-net ~]$ awk '$4 == "hust" {print $0}' ./awk.txt

    liwei  27  male     hust

    hurui  18  male     hust

    [braveyly@m-net ~]$ awk '$4 ="hust" {print $0}' ./awk.txt 

    liwei 27 male hust

    lijing 24 femaile hust

    hujuan 22 female hust

    hurui 18 male hust

    awk -Fchar '{action}'

    Seperate the line into different fileds by single char.

    No blank is between -F and char.

    [nick@d01 bash]$ cat sort4.txt 
    daemon:x:2:2:daemon:/sbin:/sbin/nologin
    root:x:0:0:root:/root:/bin/bash
    bin:x:1:1:bin:/bin:/sbin/nologin

    [nick@d01 bash]$ awk -F: '{print $7}' ./sort4.txt 
    /sbin/nologin
    /bin/bash
    /sbin/nologin

    -F argument indicates the separator of fields.

  • 相关阅读:
    JavaScript实现常见排序算法
    执行环境与作用域
    几种常见的三列布局,中间自适应,两边定宽
    常见的两列布局
    CodeAtlas For Sublime Text
    增加调用路径查找
    增加调用被调用个数隐喻
    sublime 插件
    分析大工程
    Jmeter 分布式测试
  • 原文地址:https://www.cnblogs.com/renrenbinbin/p/2920734.html
Copyright © 2011-2022 走看看