- 浏览: 134739 次
- 性别:
- 来自: 成都
文章分类
最新评论
【基本介绍】
awk是一款强大的对文件内容进行处理的软件,可以当作是一个脚本语言。
这里列出大概的学习框架和简单例子。
【学习列表】
1.Built-in functions for numeric operations
2.Built-in functions for String operations
3.Build-in functions for input output operations
4.awk if statement(if,if else,if else if,:?)
5.awk loops(do while,for loop,break,continue,exit)
6.Build-in variables(FS,OFS,RS,ORS,NR,NF,FILENAME,FNR)
【简单例子】
1. number operations
int log sqrt exp sin cos atan2 rand srand ...
2. string operations
index length match split sprintf sub gsub gensub substr tolower toupper
3. input output operations
close fflush system
4. if statement
5. for loop ,break continue
6. build-in variables
FS - Input field separator variable.
OFS - Output Field Separator Variable
RS - Record Separator variable
ORS - Output Record Separator Variable
NR - Number of Records Variable
NF - Number of Fields in a record
FILENAME - Name of the current input file
FNR - Number of Records relative to the current input file
【参考链接】
http://www.thegeekstuff.com/tag/awk-tutorial-examples/
http://www.math.utah.edu/docs/info/gawk_13.html
awk是一款强大的对文件内容进行处理的软件,可以当作是一个脚本语言。
这里列出大概的学习框架和简单例子。
【学习列表】
1.Built-in functions for numeric operations
2.Built-in functions for String operations
3.Build-in functions for input output operations
4.awk if statement(if,if else,if else if,:?)
5.awk loops(do while,for loop,break,continue,exit)
6.Build-in variables(FS,OFS,RS,ORS,NR,NF,FILENAME,FNR)
【简单例子】
1. number operations
int log sqrt exp sin cos atan2 rand srand ...
$cat rand.awk BEGIN { while(i<1000) { n = int(rand()*100); rnd[n]++; i++; } for(i=0;i<=100;i++) { print i,"Occured", rnd[i], "times"; } } $
2. string operations
index length match split sprintf sub gsub gensub substr tolower toupper
[root@pandaVM script]# awk 'BEGIN{str="daabaaa" ;sub(/a/,"c&c",str) ;print str}' dcacabaaa
3. input output operations
close fflush system
[root@pandaVM script]# awk 'BEGIN{print date}' [root@pandaVM script]# awk 'BEGIN{system("date")}' Tue Oct 21 10:40:16 CST 2014
4. if statement
$ awk '{ if ($3 >=35 && $4 >= 35 && $5 >= 35) print $0,"=>","Pass"; else print $0,"=>","Fail"; }' student-marks Jones 2143 78 84 77 => Pass Gondrol 2321 56 58 45 => Pass RinRao 2122 38 37 => Fail Edwin 2537 87 97 95 => Pass Dayan 2415 30 47 => Fail
5. for loop ,break continue
$ awk 'BEGIN{ count=1; do print "This gets printed at least once"; while(count!=1) }' This gets printed at least once
6. build-in variables
FS - Input field separator variable.
OFS - Output Field Separator Variable
RS - Record Separator variable
ORS - Output Record Separator Variable
NR - Number of Records Variable
NF - Number of Fields in a record
FILENAME - Name of the current input file
FNR - Number of Records relative to the current input file
$ awk -F':' 'BEGIN{OFS="=";} {print $3,$4;}' /etc/passwd 41=41 100=101 101=102 103=7 105=111 110=116 111=117 112=119
【参考链接】
http://www.thegeekstuff.com/tag/awk-tutorial-examples/
http://www.math.utah.edu/docs/info/gawk_13.html
发表评论
-
linux shell - 远端修改非root密码
2015-01-09 20:40 955【基本介绍】 通过远端修改普通用户密码,而passwd --s ... -
linux shell - broken pip error
2015-01-07 15:36 2664【基本介绍】 这里我们介绍发生broken pipe错误的原因 ... -
linux locate - find files by name
2014-12-17 17:46 560【基本介绍】 这里我们介绍locate命令,用来查找文件。 ... -
linux ssh - GSSAPIAuthentication
2014-12-10 14:58 2000【基本介绍】 最近公司搬家,发现合作伙伴的服务器的用ftp工具 ... -
linux tar - 压缩解压
2014-12-01 16:04 969【基本介绍】 今天遇到要添加文件到tar文件里面,所以在这里介 ... -
linux parameter substitution - 字符串/变量处理
2014-11-17 15:56 777【基本介绍】 这里我们介绍bash里面对字符串,变量等的替换等 ... -
linux netstat - status状态描述
2014-11-14 17:59 1112【基本介绍】 这里介绍netstat命令返回的结果status ... -
linux set - set variables and set positional parameters
2014-11-10 18:26 406【基本介绍】 set是shell的内置命令。可以用来设置修改变 ... -
linux nc - arbitrary TCP and UDP connections and listens
2014-10-31 17:46 758【基本介绍】 nc是可以打开任意端口的TCP/UDP连接和监听 ... -
linux 报错集 - Cannot retrieve metalink for repository: epel. Please verify its pat
2014-10-29 15:12 925【基本介绍】 运行yum报错Error: Cannot ret ... -
linux ps - processes
2014-10-20 14:17 1219【基本介绍】 ps - report a snapshot o ... -
linux lsof - list open files
2014-10-17 17:31 711【基本介绍】 lsof - list open files I ... -
linux - 网络连接状态
2014-10-13 11:00 1350【基本情况】 这里介绍 ... -
linux netstat - Print network connections, routing tables, interface statistics,
2014-10-13 10:37 978【基本介绍】 netstat - Print network ... -
linux vmstat - Report virtual memory statistics
2014-10-10 17:39 692【基本介绍】 vmstat - Report virtual ... -
linux yum - yum warning: rpmts_HdrFromFdno
2014-10-09 15:08 560【基本介绍】 在yum安装软件的时候有时候会报warning: ... -
Linux ip subnet mask - 网段分析
2014-09-24 19:22 1292【基本介绍】 网段的分析可以帮助我们查看两个局域地址是否可以互 ... -
linux curl - curl 上传下载
2014-09-19 11:45 2074【基本介绍】 curl is a tool to tra ... -
linux mkpasswd - 密码生成器
2014-09-18 17:18 1380【基本介绍】 作为linux admin要经常创建用户,并初始 ... -
linux dd - dd测试硬盘速度
2014-09-05 18:42 816【基本介绍】 这里我们使用dd命令来测试硬盘的读写速度 dd ...
相关推荐
awk tutorial and introduction 英文版 网上的连接 http://www.askapache.com/linux/awk-tutorial.html
Awk is an extremely versatile programming language for working on files. We'll teach you just enough to understand the examples in this page, plus a smidgen. The examples given below have the ...
The book begins with an overview and a tutorial that demonstrate a progression in functionality from grep to sed to awk. sed and awk share a similar command-line syntax, accepting user instructions in...
Awk入门教程。作者 Bruce Barnett 注:英文版。以下是目录 Why learn AWK? Basic Structure Executing an AWK script Which shell to use with AWK? Dynamic Variables The Essential Syntax of AWK ...
AWK Tutorial Guide,这是一本AWK学习指引,其重点在于解决一下问题: AWK适于解决那些问题?AWK常见的解决模式是什么?
Whether you are starting out with awk or are an experienced developer, this book will help you extend the reach of your awk scripts., This tutorial covers the entire spectrum of awk script ...
It begins with a tutorial that shows how easy AWK is to use. The tutorial is followed by a comprehensive manual for the new version of AWK. Subsequent chapters illustrate the language by a range of ...
描述通过针对HackerRank上Linux Shell挑战的相关学习资源,汇编了所有容易,中等和困难挑战的解决方案。 域包括:重击挑战数字挑战性解决方案1个2个3解决方案4 用数字循环解决方案5 数字世界解决方案6 比较数字解决...
鸟哥Linux教程推荐的官方文献,已翻译成简体中文。
A step-by-step tutorial to automate routine tasks by developing scripts Book Description Linux is the most powerful and universally adopted OS. Shell is a program that gives the user direct ...
two of the most popular string processing languages (awk and sed). We’ll also look at the topic of parser generation using GNU Flex and Bison utilities (lex and yacc- compatible parser generator). ...
GNU / Linux系统中的生物计算入门讲习班 欢迎来到 GNU / Linux 系统中的生物计算介绍性研讨会! 研讨会的理由和目标 基因组学工作是在高性能 UNIX 或 GNU/Linux 服务器上完成的。 因此,我建议您在开始学术培训时...
1In this book, Unix is shorthand for “UNIX, Linux, and related operating systems,” as detailed in the “Essential terminology” section of “About this book.” 2See this book’s glossary for the ...
PostgreSQL (htmls Inc.)
介绍用户,组和权限硬件和软件炮弹文件和文件系统 sed awk 硬存储设备和文件系统文件系统硬盘和分区文件系统/ tmp Craft.io流程Craft.io流程自动化流程图形和多媒体Xorg 声音的联网联网安全安全工具安全主机地点...
The book closes with a tutorial on making a programming language parser with yacc and how to use troff with ms and mm to format documents, the preprocessors tbl, eqn, and pic, and making man pages ...
This combination reference and tutorial provides a comprehensive yet concise look at UNIX for users of Mac OS X. The book is fully up-to-date with the 10.4 (Tiger) release of OS X which is built on ...