首页  

awk 内建变量     所属分类 shell 浏览量 268
FS OFS RS ORS NR NR FNR

FS  Field Separator
OFS Output Field Separator
RS  Record Separator
ORS Output Record Separator
NR  Number of Record
NF  Number for Field
FNR 当前输入文件记录数
FILENAME  当前输入文件名

awk读取多个文件时
NR  已经处理过的总记录数目  
FNR 当前文件的记录数

awk -F 'FS' 'commands' inputfilename
awk 'BEGIN{FS="FS";}'


show_passwd.awk
BEGIN{
FS=":";
print "Name\tUserID\tGroupID\tHomeDirectory";
}
{
    print $1"\t"$3"\t"$4"\t"$6;
}
END {
    print NR,"Records Processed";
}

$ awk -f show_passwd.awk /etc/passwd


awk -F':' '{print $3,$4;}' /etc/passwd
awk -F':' 'BEGIN{OFS="=";} {print $3,$4;}' /etc/passwd

awk '{print "Processing Record - ",NR;}END {print NR, " Records are processed";}' hello.txt

awk '{print NR,"->",NF}' xxx
awk '{print FILENAME}' xxx

上一篇     下一篇
采光权简介

shell执行时提示 $‘\r‘ 错误

linux awk 实例

置身事内笔记

资产证券化 MBS和ABS

2008金融危机