AWK Vs NAWK Vs GAWK

 Awk是操作和处理文本文件的强有力的语言,当行在文本文件以记录的格式最有帮助,等。一个记录包含各种各样的域被分隔符隔开即使当输入文件不是记录格式的,你仍然可以使用awk做一些基本的数据处理,你可以用aws写程序逻辑甚至没有输入文件需要处理。

 

简而言之,awk是强有力的语言,可以随手做日常工作。

 

如果你没接触过awk,开始读这个awk 介绍教程,是awk系列教程的一部分。

 

Learning curve on AWK is much smaller than the learning curve on any other languages. If you know C program already, you’ll appreciate how simple and easy it is to learn AWK.

学习曲线在awk比学习其他语言的曲线小很多。如果你已经会用C语言了,你会知道学习awk室多么的简单多么的容易。

AWK was originally written by three developers — A. Aho, B. W. Kernighan and P. Weinberger. So, the name AWK came from the initials of those three developers.

The following are the three variations of AWK:

awk起初是由三个开发者一起写的— A. Aho, B. W. Kernighan and P. Weinberger.所以,awk来自于起始的三个开发者,接下来的是其三个变种。

1. Awk

awk起初由A. Aho, B. W. Kernighan and P. Weinberger所著

2. Nawk

NAWK代表 “New AWK” 这个是AT&T版本的awk

3. Gawk

GAWK代表“GNU AWK”.所有的linux发行版都带有gawk。这个是和awk,nawk完全兼容的。

在linux系统上,无论输入awk或gawk,awk链接到gawk显示在linux系统。

 

# ls -l /bin/awk /usr/bin/awk
lrwxrwxrwx 1 root root  4 Jan  5 23:13 /bin/awk -> gawk
lrwxrwxrwx 1 root root 14 Jan  5 23:13 /usr/bin/awk -> ../../bin/gawk

 

接下来的表概括了可用版本的不同特色。正如你所见到的,gawk是一个超集包含了起初的awk和nawk的特色.

Awk Vs Nawk Vs Gawk

下载awk vs nawk vs gawk的不同在 下面的文档中。

下面基本的内疚变量 fs,ofs,rs,ors,nr,nf,和filename 在所有的awk版本可用

 

特色描述AWKNAWKGAWK
FS输入域分割符YesYesYes
OFS输出域分割符YesYesYes
RS记录分割符YesYesYes
ORS输出记录分割符YesYesYes
NR记录的个数YesYesYes
NF记录的域的个数YesYesYes
FILENAME包含了当前正在处理的输入文件                          YesYesYes

接下来的特色在起初的awk中不可用。他们是可用的在nawk 和/或 gawk像下面的:

特色描述NAWKGAWK
FNR记录个数的文件YesYes
ARGCTotal number or arguments passed to awk scriptYesYes
ARGVArray containing all awk script argumentsYesYes
ARGINDIndex to ARGV to retrieve the current file name Yes
SUBSEPSubscript separator for array indexesYesYes
RSTARTMatch function sets RSTART with the starting location of str1 in str2YesYes
RLENGTHMatch function sets RLENGTH with length of the str1YesYes
OFMTAwk uses this to decide how to print values. Default is “%.6g”YesYes
ENVIRONArray containing all environment variables and values Yes
IGNORECASEDefault is 0. When set to 1, it is case insensitive for string and reg-ex comparisons. Yes
ERRNOContains error message of an I/O operation. e.g. while using getline function. Yes
BINMODE nSet binary mode for I/O. n can be 1 (input files), 2(output files), or 3(all files) Yes
CONVFMTThe format used while converting number to string. Yes
FIELDWIDTHS nn is a space delimited number that indicates the column widths. If this is available, gawk uses this instead of FS. Yes
LINT nn can be a number. When n is a nonzero number (indicating true), gawk will displays fatal, invalid, or warning lint messages (same as –lint command line) Yes
TEXTDOMAINThis is used for internationalization. Yes
sub(str1,str2,var)In the input string (var), str1 is replaced with str2, and output is stored back in varYesYes
gsub(str1,str2,var)Same as sub, but global. It does multiple substitutions on the same input string (var).YesYes
match(str1,str2)Returns positive number when str1 is present in str2.YesYes
getline < fileRead next line from another input-file. Sets $0, NFYesYes
getline var < fileRead next line from another input-file and store it in variable (var)YesYes
toupper(str)字符串转换为大写格式 Yes
tolower(str)字符串转换为小写格式 Yes
|&两种交流方式在awk和外部处理 Yes
systime()Current time in epoch time. Combine with strftime. e.g. print strftime(“%c”,systime()) Yes

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值