x

awk用法,爱威康

2024-06-17 21:58:24编辑:浮木

awk的作用awk的主要作用是文本处理

awk的语法` awk ' begin { awk-commands }/pattern/{ awk-commands } end { awk-commands } }

awk的结构awk首先执行BEGIN的内容,然后读取一行文本,再执行awk命令的内容,最后执行END的内容

要赋值awk变量,请输入-v参数awk-vname=' test ' ' begin { print name } ' # name :变量名#print name :打印变量name # awk内置变量fs :使用itrepresentsthe ( inppresentsthe )的fieldseparatoranditsdefaultvalueisspacenf:itrepresentsthenumberoffieldsienf ntsthenumberoftheche record.ofs:itrepresentstheoutputfieldseparatoranditsdefaultvalueisspace.ors:itrepresentststheoutputputrtputtrattttttttprespace

awkcontrolflowandloopif ( condition ) actionfor (初始化); 编码; increment/decrement (操作#注意:在for中,使用分号分隔awkbuilt-infunctionsgsub(regex,sub )。 string ( itreplaceseveryoccurrenceofregexwiththegivenstring ) sub ).thethirdparameterisoptional.ifitisomitted,then$0

示例$ echo ' this isa test '|awk ' { print $3} ' a [ root @ d ] # echo1| awk ' begin { print ' start ' }/1/{ print } body

更多排行: