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
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    【技术评网】说说豆瓣的URL设计
    在这一刻,还是忍不住满眼泪水
    装Sybase,装WAS 6.1的时候报错java.exe损坏的图象
    JasperRepor导出报表通用类
    XSS跨站攻击
    sql 脚本
    解决在无线网络下本机无法连接linux(红帽)虚拟机问题
    pl /sql导入导出表结构,表数据,sql脚本
    asp.net关于WEB端用户重复提交问题。禁用服务器控件按钮问题。
    MQ命令学习总结大全MQ常用命令
  • 原文地址:https://www.cnblogs.com/bluescorpio/p/1642612.html
Copyright © 2011-2022 走看看