zoukankan      html  css  js  c++  java
  • Linux /awk/ Usage

    Linux <i>awk</i> Usage

    Linux awk Usage

    In this post, I am going to record the common patterns of using awk, the amazing tool for processing file.
    Assume I have a file (bb) with the following contents:
    70 23 2 757 35 3 765 56 3 765 56 1 23 4 11 3

    1 Sum a specific column:

    awk '{sum += $1} END {print sum}' bb

    2 Sum the columns of the lines with additional conditions(starting with 7):

    1: awk '/^7/ {print $2}' bb | awk '{sum += $1} END {print sum}'
    

    3 Output the line whose value in the 3rd column is 1:

    1: awk '$3 == 1' bb
    

    4 Output the line whose $1 < 80 and $2 > 20:

    1: awk '{$1<80 && $2>20;print $3}' bb
    

    5 Count the lines starting with 7:

    1: awk '/^7/ {x++;} END {print x}' bb
    

    6 Output the line containg number 765

    1: awk '/765/' bb
    

    7 Output the line containing number 765 with the line number in front of that line:

    1: awk '/765/ {print NR":"$0}' bb
    

    In the above command, the NR is the built-in variable that represents the line being processed, the $0 refers to the whole line.9

    8 Output the lines not containing number 765:

    1: awk '!/765/' bb
    

    Author: wujing

    Created: 2015-01-23 五 21:22

    Emacs 24.3.1 (Org mode 8.2.10)

  • 相关阅读:
    如何对抗信息茧房?
    术语
    2021.07.17软件更新公告
    【C#】C#中使用GDAL3(二):Windows下读写Shape文件及超详细解决中文乱码问题
    【C#】C#中使用GDAL3(一):Windows下超详细编译C#版GDAL3.3.0(VS2015+.NET 4+32位/64位)
    k8s使用私有镜像仓库
    四、Abp vNext 基础篇丨领域构建
    Abp vNext 番外篇-疑难杂症丨认证授权
    三、Abp vNext 基础篇丨分层架构
    知识全聚集 .Net Core 目录篇
  • 原文地址:https://www.cnblogs.com/wujingcqu/p/4245084.html
Copyright © 2011-2022 走看看