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.

  • 相关阅读:
    网页CSS2
    C#(1)—类型、常量及变量
    进制转化
    12月26日提纲
    12月24日笔记
    12月23日笔记
    12月22日笔记
    12月21日笔记
    12月20日笔记
    break、continue与数组
  • 原文地址:https://www.cnblogs.com/renrenbinbin/p/2920734.html
Copyright © 2011-2022 走看看