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.

  • 相关阅读:
    Lambda表达式
    java中解决小数精度问题
    [Unity]-黑魂复刻-动画 001
    kuka Virtual Remote pendant 连接使用
    C# 操作 pg 数据库
    C#常用字符串操作
    Go学习笔记之相关资源
    Go学习笔记之常用命令
    Go学习笔记之安装
    nginx学习笔记之安装
  • 原文地址:https://www.cnblogs.com/renrenbinbin/p/2920734.html
Copyright © 2011-2022 走看看