Gawk是GNU awk,是awk遵循开源的实现。而gawk是一款功能强大的文本处理工具,这款软件自成体系,实际上就是一个用于处理文本的编程语言工具。

#官方网站关于awk和gawk的文档
https://www.gnu.org/software/gawk/manual/gawk.html

以下均来自CentOS7系统中关于Gawk的解释内容

Usage: gawk [POSIX or GNU style options] -f progfile [--] file ...
Usage: gawk [POSIX or GNU style options] [--] 'program' file ...
POSIX options:          GNU long options: (standard)-f progfile             --file=progfile-F fs                   --field-separator=fs-v var=val              --assign=var=val
Short options:          GNU long options: (extensions)-b                      --characters-as-bytes-c                      --traditional-C                      --copyright-d[file]                --dump-variables[=file]-e 'program-text'       --source='program-text'-E file                 --exec=file-g                      --gen-pot-h                      --help-L [fatal]              --lint[=fatal]-n                      --non-decimal-data-N                      --use-lc-numeric-O                      --optimize-p[file]                --profile[=file]-P                      --posix-r                      --re-interval-S                      --sandbox-t                      --lint-old-V                      --versionTo report bugs, see node `Bugs' in `gawk.info', which is
section `Reporting Problems and Bugs' in the printed version.gawk is a pattern scanning and processing language.
By default it reads standard input and writes standard output.Examples:gawk '{ sum += $1 }; END { print sum }' filegawk -F: '{ print $1 }' /etc/passwdGAWK(1)                                                                      Utility Commands                                                                     GAWK(1)NAMEgawk - pattern scanning and processing languageSYNOPSISgawk [ POSIX or GNU style options ] -f program-file [ -- ] file ...gawk [ POSIX or GNU style options ] [ -- ] program-text file ...pgawk [ POSIX or GNU style options ] -f program-file [ -- ] file ...pgawk [ POSIX or GNU style options ] [ -- ] program-text file ...dgawk [ POSIX or GNU style options ] -f program-file [ -- ] file ...DESCRIPTIONGawk  is the GNU Project's implementation of the AWK programming language.  It conforms to the definition of the language in the POSIX 1003.1 Standard.  This ver鈥[msion in turn is based on the description in The AWK Programming Language, by Aho, Kernighan, and Weinberger.  Gawk provides the additional features found  in  thecurrent version of UNIX awk and a number of GNU-specific extensions.The  command  line consists of options to gawk itself, the AWK program text (if not supplied via the -f or --file options), and values to be made available in theARGC and ARGV pre-defined AWK variables.Pgawk is the profiling version of gawk.  It is identical in every way to gawk, except that programs run more slowly, and it automatically  produces  an  executionprofile in the file awkprof.out when done.  See the --profile option, below.Dgawk  is  an awk debugger. Instead of running the program directly, it loads the AWK source code and then prompts for debugging commands.  Unlike gawk and pgawk,dgawk only processes AWK program source provided with the -f option.  The debugger is documented in GAWK: Effective AWK Programming.OPTION FORMATGawk options may be either traditional POSIX-style one letter options, or GNU-style long options.  POSIX options start with a single “-”, while long options startwith “--”.  Long options are provided for both GNU-specific features and for POSIX-mandated features.Gawk- specific options are typically used in long-option form.  Arguments to long options are either joined with the option by an = sign, with no intervening spa‐ces, or they may be provided in the next command line argument.  Long options may be abbreviated, as long as the abbreviation remains unique.Additionally, each long option has a corresponding short option, so that the option's functionality may be used from within #!  executable scripts.OPTIONSGawk accepts the following options.  Standard options are listed first, followed by options for gawk extensions, listed alphabetically by short option.-f program-file--file program-fileRead the AWK program source from the file program-file, instead of from the first command line argument.  Multiple -f (or --file) options may be used.-F fs--field-separator fsUse fs for the input field separator (the value of the FS predefined variable).-v var=val--assign var=valAssign the value val to the variable var, before execution of the program begins.  Such variable values are available to the BEGIN block of an AWK program.-b--characters-as-bytesTreat all input data as single-byte characters. In other words, don't pay any attention to the locale information when attempting  to  process  strings  asmultibyte characters.  The --posix option overrides this one.-c--traditionalRun  in  compatibility  mode.   In  compatibility  mode, gawk behaves identically to UNIX awk; none of the GNU-specific extensions are recognized.  See GNUEXTENSIONS, below, for more information.-C--copyrightPrint the short version of the GNU copyright information message on the standard output and exit successfully.-d[file]--dump-variables[=file]Print a sorted list of global variables, their types and final values to file.  If no file is provided, gawk uses a file named awkvars.out in  the  currentdirectory.Having  a  list  of all the global variables is a good way to look for typographical errors in your programs.  You would also use this option if you have alarge program with a lot of functions, and you want to be sure that your functions don't inadvertently use global variables that you  meant  to  be  local.(This is a particularly easy mistake to make with simple variable names like i, j, and so on.)-e program-text--source program-textUse program-text as AWK program source code.  This option allows the easy intermixing of library functions (used via the -f and --file options) with sourcecode entered on the command line.  It is intended primarily for medium to large AWK programs used in shell scripts.-E file--exec fileSimilar to -f, however, this is option is the last one processed.  This should be used with #!  scripts, particularly for CGI applications, to avoid  pass‐ing in options or source code (!) on the command line from a URL.  This option disables command-line variable assignments.-g--gen-potScan  and parse the AWK program, and generate a GNU .pot (Portable Object Template) format file on standard output with entries for all localizable stringsin the program.  The program itself is not executed.  See the GNU gettext distribution for more information on .pot files.-h--help Print a relatively short summary of the available options on the standard output.  (Per the GNU Coding Standards, these options cause  an  immediate,  suc‐cessful exit.)-L [value]--lint[=value]Provide  warnings about constructs that are dubious or non-portable to other AWK implementations.  With an optional argument of fatal, lint warnings becomefatal errors.  This may be drastic, but its use will certainly encourage the development of cleaner AWK programs.  With an optional  argument  of  invalid,only warnings about things that are actually invalid are issued. (This is not fully implemented yet.)-n--non-decimal-dataRecognize octal and hexadecimal values in input data.  Use this option with great caution!-N--use-lc-numericThis forces gawk to use the locale's decimal point character when parsing input data.  Although the POSIX standard requires this behavior, and gawk does sowhen --posix is in effect, the default is to follow traditional behavior and use a period as the decimal point, even in locales where the period is not thedecimal point character.  This option overrides the default behavior, without the full draconian strictness of the --posix option.-O--optimizeEnable  optimizations upon the internal representation of the program.  Currently, this includes just simple constant-folding. The gawk maintainer hopes toadd additional optimizations over time.-p[prof_file]--profile[=prof_file]Send profiling data to prof_file.  The default is awkprof.out.  When run with gawk, the profile is just a “pretty printed” version of  the  program.   Whenrun  with  pgawk,  the profile contains execution counts of each statement in the program in the left margin and function call counts for each user-definedfunction.-P--posixThis turns on compatibility mode, with the following additional restrictions:· \x escape sequences are not recognized.· Only space and tab act as field separators when FS is set to a single space, newline does not.· You cannot continue lines after ?  and :.· The synonym func for the keyword function is not recognized.· The operators ** and **= cannot be used in place of ^ and ^=.-r--re-intervalEnable the use of interval expressions in regular expression matching (see Regular Expressions, below).  Interval expressions were not traditionally avail‐able  in  the AWK language.  The POSIX standard added them, to make awk and egrep consistent with each other.  They are enabled by default, but this optionremains for use with --traditional.-R--command fileDgawk only.  Read stored debugger commands from file.-S--sandboxRuns gawk in sandbox mode, disabling the system() function, input redirection with getline, output redirection with print and printf, and  loading  dynamicextensions.  Command execution (through pipelines) is also disabled.  This effectively blocks a script from accessing local resources (except for the filesspecified on the command line).-t--lint-oldProvide warnings about constructs that are not portable to the original version of Unix awk.-V--versionPrint version information for this particular copy of gawk on the standard output.  This is useful mainly for knowing if the current copy of gawk  on  yoursystem  is up to date with respect to whatever the Free Software Foundation is distributing.  This is also useful when reporting bugs.  (Per the GNU CodingStandards, these options cause an immediate, successful exit.)--     Signal the end of options. This is useful to allow further arguments to the AWK program itself to start with a “-”.  This  provides  consistency  with  theargument parsing convention used by most other POSIX programs.In  compatibility  mode,  any  other  options  are flagged as invalid, but are otherwise ignored.  In normal operation, as long as program text has been supplied,unknown options are passed on to the AWK program in the ARGV array for processing.  This is particularly useful for running AWK programs via the  “#!”  executableinterpreter mechanism.AWK PROGRAM EXECUTIONAn AWK program consists of a sequence of pattern-action statements and optional function definitions.@include "filename" pattern   { action statements }function name(parameter list) { statements }Gawk  first reads the program source from the program-file(s) if specified, from arguments to --source, or from the first non-option argument on the command line.The -f and --source options may be used multiple times on the command line.  Gawk reads the program text as if all the program-files and command line source textshad  been  concatenated  together.  This is useful for building libraries of AWK functions, without having to include them in each new AWK program that uses them.It also provides the ability to mix library functions with command line programs.In addition, lines beginning with @include may be used to include other source files into your program, making library use even easier.The environment variable AWKPATH specifies a search path to use when finding source files named with the -f option.  If this variable does not exist, the  defaultpath  is  ".:/usr/local/share/awk".  (The actual directory may vary, depending upon how gawk was built and installed.)  If a file name given to the -f option con‐tains a “/” character, no path search is performed.Gawk executes AWK programs in the following order.  First, all variable assignments specified via the -v option are performed.  Next, gawk  compiles  the  programinto  an  internal  form.   Then,  gawk  executes  the  code  in  the  BEGIN block(s) (if any), and then proceeds to read each file named in the ARGV array (up toARGV[ARGC]).  If there are no files named on the command line, gawk reads the standard input.If a filename on the command line has the form var=val it is treated as a variable assignment.  The variable var will be assigned the value  val.   (This  happensafter  any  BEGIN  block(s) have been run.)  Command line variable assignment is most useful for dynamically assigning values to the variables AWK uses to controlhow input is broken into fields and records.  It is also useful for controlling state if multiple passes are needed over a single data file.If the value of a particular element of ARGV is empty (""), gawk skips over it.For each input file, if a BEGINFILE rule exists, gawk executes the associated code before processing the contents of the file. Similarly, gawk executes  the  codeassociated with ENDFILE after processing the file.For  each record in the input, gawk tests to see if it matches any pattern in the AWK program.  For each pattern that the record matches, the associated action isexecuted.  The patterns are tested in the order they occur in the program.Finally, after all the input is exhausted, gawk executes the code in the END block(s) (if any).Command Line DirectoriesAccording to POSIX, files named on the awk command line must be text files.  The behavior is ``undefined'' if they are not.  Most versions of awk treat  a  direc‐tory on the command line as a fatal error.Starting  with  version  4.0  of  gawk,  a  directory on the command line produces a warning, but is otherwise skipped.  If either of the --posix or --traditionaloptions is given, then gawk reverts to treating directories on the command line as a fatal error.VARIABLES, RECORDS AND FIELDSAWK variables are dynamic; they come into existence when they are first used.  Their values are either floating-point numbers or strings, or both, depending  uponhow  they  are  used.   AWK also has one dimensional arrays; arrays with multiple dimensions may be simulated.  Several pre-defined variables are set as a programruns; these are described as needed and summarized below.RecordsNormally, records are separated by newline characters.  You can control how records are separated by assigning values to the built-in variable RS.  If RS  is  anysingle  character, that character separates records.  Otherwise, RS is a regular expression.  Text in the input that matches this regular expression separates therecord.  However, in compatibility mode, only the first character of its string value is used for separating records.  If RS is  set  to  the  null  string,  thenrecords are separated by blank lines.  When RS is set to the null string, the newline character always acts as a field separator, in addition to whatever value FSmay have.FieldsAs each input record is read, gawk splits the record into fields, using the value of the FS variable as the field separator.  If FS is a single character,  fieldsare separated by that character.  If FS is the null string, then each individual character becomes a separate field.  Otherwise, FS is expected to be a full regu‐lar expression.  In the special case that FS is a single space, fields are separated by runs of spaces and/or tabs and/or newlines.  (But see  the  section  POSIXCOMPATIBILITY, below).  NOTE: The value of IGNORECASE (see below) also affects how fields are split

Linux系统下Gawk工具的使用方式相关推荐

  1. 【代理设置】Linux Windows 系统下各工具设置代理方式笔记(整理中)

    背景:公司局域网环境,只提供代理服务器&代理账号的方式上网.Linux服务器各种工具代理设置方法整理如下: 1. 命令行界面设置代理 命令行界面的一般代理设置方法:在profile文件中设置相 ...

  2. linux系统下聊天工具,linux系统环境下如何使用amsn聊天工具_linux教程

    amsn这一款在linux下的Msn就不多介绍了,0.95版出来后加入了摄像头,在加上其文件传输功能,你还留恋于gaim么? 经过多天的搜索和尝试,终于在Fedora Core3里用上amsn了.其实 ...

  3. linux系统下html工具,Linux下五个好用的HTML编缉器

    Quanta Plus Quanta Plus原 名叫Quanta,是一个WEB的集成开发环境(IDE),可以用于HTML.XHTML.CSS.XML.PHP和其它基于XML的语言或者是脚本语言 的开 ...

  4. Linux系统下常见性能分析工具的使用

    在前面的文章中,我简单介绍了影响linux性能的几个方面以及如何解决这些方面的问题,但是如何才能从系统上发现是某个方面或某几个方面出现问题了呢,这就需要使用linux系统提供的几个常用性能分析工具,下 ...

  5. linux 性能教程,Linux系统下常见性能分析工具的使用

    在前面的文章中,我简单介绍了影响linux性能的几个方面以及如何解决这些方面的问题,但是如何才能从系统上发现是某个方面或某几个方面出现问题了呢,这就需要使用linux系统提供的几个常用性能分析工具,下 ...

  6. 分析linux系统的运行性能,Linux系统下常见性能分析工具的使用

    在前面的文章中,我简单介绍了影响linux性能的几个方面以及如何解决这些方面的问题,但是如何才能从系统上发现是某个方面或某几个方面出现问题了呢,这就需要使用linux系统提供的几个常用性能分析工具,下 ...

  7. linux中split分割文件打开方式,Linux系统下使用split命令分割大文件 (转载)

    [小蜗牛闲情之作 ] 我想给一个朋友传一个大视频,有几百M,尝试多种传输办法失败后,最后想到的是把视频切开一片片"邮递"过去给他,让它自己组装起来吧. [root@pps publ ...

  8. Linux系统下的RZSZ(文件传输工具)

    yum install lrzsz.i386 (最方便的方法)  Linux系统下传输方式很多,比如:通过FTP SFTP - 等等.linux服务器大多是通过ssh客户端来进行远程的登陆和管理的,使 ...

  9. Linux系统下工具软件的安装

    Linux系统下软件的几种安装方法 1 背景 2 环境 3 安装工具 3.1 准备工作 3.1.1 更新系统 3.2 系统工具 3.2.1 elementary-tweaks 工具 3.2.3 Edd ...

最新文章

  1. 985博士:导师是院士,直到毕业,我们都没单独说过一句话
  2. clientHeight , scrollHeight , offsetHeight之间的区别及兼容方案
  3. hdu4901 枚举状态(找集合对S(xor) ==T(and))
  4. 9本java程序员必读的书(附下载地址)
  5. 人体姿态估计算法之open pose
  6. netbeans7.4_NetBeans 7.2引入了TestNG
  7. python easy install 编译_python安装easy_install和pip
  8. accessibility-service 高版本无法编译_今天我把APP的编译速度缩短了近5倍
  9. ASP.NET Core搭建多层网站架构【11-WebApi统一处理返回值、异常】
  10. 尝试使用iReport4.7(基于Ubuntu Desktop 12.04 LTS)
  11. 华硕笔记本 X550JD4710HQ
  12. OsharpNS轻量级.net core快速开发框架简明入门教程-多上下文配置(多个数据库的使用)...
  13. 手写板(数位板)如何和希沃白板5无缝切换
  14. MAC使用Safari浏览器仿真IE
  15. ltp测试操作步详解(压力测试网站最详、下载、使用)
  16. 博客留言外链是否有用?
  17. 实现WinForm的DataGridView折叠功能(非原创,仅供收藏)
  18. 微信小程序不同身份登录,显示不同的tabbar(导航栏)
  19. 网络渗透测试实验二(网络扫描与网络侦察)
  20. Spring Boot 综合示例-整合thymeleaf、mybatis、shiro、logging、cache开发一个文章发布管理系统...

热门文章

  1. QUIC协议原理分析
  2. 航空5G通信基建加速:高空追剧、打“农药”在路上
  3. sonatype repository oss
  4. 手把手教你搭建深度学习开发环境(Tensorflow)
  5. 盘点好用的3D渲染软件,哪个更适合你?
  6. QT之QSetting的使用
  7. 大数据应用实践1:基于开源架构的股票行情分析与预测
  8. python简单的计算方法,【python入门级课程】做一台简单的计算器
  9. 前端工程师很有必要学习Node
  10. 学校机房电脑控制如何彻底解除