首页 > AWK 学习手札之一: an AWK tutorial

AWK 学习手札之一: an AWK tutorial

AWK 学习手札之一: an AWK tutorial

these article base on the AWK programming language by alfred v.aho brian W.Kernighan and Peter J.Weinberger.

1.1 geting start:

generate a file name emp.data, which contain the name of employee, pay rate in dollar perl hour and worked hour, one employee record per line

Beth    4.00    0

Dan    3.75    0

Kathy    4.00    10

Mark    5.00    20

Mary    5.50    22

Susie    4.25    18

now you want to print the name and pay for everyone who worked more than zero hour, type the comman line:

1  awk '$3>0{print $1,$2*$3}' emp.data

your will get this output:

Kathy 40

Mark 100

Mary 121

Susie 76.5

the part inside the quotes is the complete awk program. it consists of a single pattern-action statement.

the pattern: $3>0, matchs every input line in which the third column, or field, is greater than zero, and the action

{print $1,$2*$3}

prints the first field and theproduct of the second and third fields of each matched line.

if you want to print the name of those employees who did not work, type this command line:

1  awk '$3>0{print $1,$2*$3}' emp.data

you will get:

Beth

Dan

1.2 the structure of an awk program

each awk program in this chapter is a sequence of one or more pattern-action statements:

pattern {action}

the basic operation of awk is to scan a sequence of input lines one after another, searching for lines that are matched by any of the patterns in the program.

1.3 running awk programming

awk 'program' input files

awk 'program'

posted on 2014-06-10 16:19 韩英武 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/hanleilei/p/2291203.html

更多相关:

  • 上篇笔记中梳理了一把 resolver 和 balancer,这里顺着前面的流程走一遍入口的 ClientConn 对象。ClientConn// ClientConn represents a virtual connection to a conceptual endpoint, to // perform RPCs. // //...

  • 我的实验是基于PSPNet模型实现二维图像的语义分割,下面的代码直接从得到的h5文件开始往下做。。。 也不知道是自己的检索能力出现了问题还是咋回事,搜遍全网都没有可以直接拿来用的语义分割代码,东拼西凑,算是搞成功了。 实验平台:Windows、VS2015、Tensorflow1.8 api、Python3.6 具体的流程为:...

  • Path Tracing 懒得翻译了,相信搞图形学的人都能看得懂,2333 Path Tracing is a rendering algorithm similar to ray tracing in which rays are cast from a virtual camera and traced through a s...

  • configure_file( [COPYONLY] [ESCAPE_QUOTES] [@ONLY][NEWLINE_STYLE [UNIX|DOS|WIN32|LF|CRLF] ]) 我遇到的是 configure_file(config/config.in ${CMAKE_SOURCE_DIR}/...

  •     直接复制以下代码创建一个名为settings.xml的文件,放到C:UsersAdministrator.m2下即可