zoukankan      html  css  js  c++  java
  • AWK学习笔记一:入门

         AWK is a programming language that is designed for processing text-based data, either in files or data streams, and was created at Bell Labs in the 1970s.

    Basic Concept of AWK:


    A file consists of records, which by default are the lines of the file. One line becomes one record.
    FS: The special variable FS (Field Separator) determines how awk will split up each record into fields.
    $n: Integer variables can be used to refer to fields, each filed are separated by FS.
    $0: $0 is representing the entire line.
    NF: The special variable NF tells you how many fields are in this record.
    NR: The special variable NR tells you which record this is. It is incremented each time a new record is read in.
     
    AWK One Line Command Structure
    $ awk <search pattern> {<program actions>}
    AWK searches through the input file for each line that contains the search pattern. For each of these lines found, Awk then performs the specified actions. If no search pattern is specified. Awk will match all lines in the input file, and perform the actions on each one.
    such as $ awk '{print NR,$0}' filename
    If the AWK sentence is too long, we can put it in a file and run it with
    $ awk -f program-file input-file1 input-file2 ...
    AWK Script File Structure
     awk 'BEGIN              {<initializations>}
            <search pattern 1> {<program actions>}
            <search pattern 2> {<program actions>}
            ...
            END                {<final actions>}'
        The BEGIN clause performs any initializations required before Awk starts scanning the input file. The subsequent body of the Awk program consists of a series of search patterns, each with its own program action. AWK scans each line of the input file for each search pattern, and performs the appropriate actions for each string found. Once the file has been scanned, an END clause can be used to perform any final actions required.
    作者:Shane
    出处:http://bluescorpio.cnblogs.com
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    LightProxy修改请求头、cookie
    webpack2项目中引入@vue/composition-api报错Cannot find module
    webpack2项目引入ts后报错@ ./~/vue-style-loader!./~/css-loader!./~/vue-loader/lib/style-compiler?
    mac brew 安装指定版本后 node命令找不到
    python数据类型详解
    更换Linux(CentOS) yum源
    Python读写文件
    Python异常处理try...except、raise
    Python删除空格字符串两端的空格
    python的urllib模块中的方法
  • 原文地址:https://www.cnblogs.com/bluescorpio/p/1642612.html
Copyright © 2011-2022 走看看