首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

AIX上AWK语言的操作符

2012-11-26 
AIX下AWK语言的操作符awk操作符————————————————————————————————————————————— + * / % ^ 赋值操

AIX下AWK语言的操作符

awk操作符—————————————————————————————————————————————= += *= / = %= ^ =赋值操作符?        条件表达操作符||  &&  !并,与,非< <= == != >>关系操作符+ - * / % ^算术操作符+ + --前缀和后缀——————————————————————————————————————————————1.设置输入域到域变量名awk '{name=$1;color=$4; if(color ~/Yello/)print name" " is color "color}' grade.txtP.Bunny is color Yello2.赋值比较,通常在BEGIN部分赋值a.在BEGIN中给变量名赋值awk 'BEGIN {BASELINE="27   "} {if($6<BASELINE) print $0}' grade.txtJ.Lulu     06/99  48317  green    9    24   26J.Troll    07/99  4842   Brown-3  12   26   26b.在关系操作中使用实际数值awk '{if($6 < 27) print $0}' grade.txtJ.Lulu     06/99  48317  green    9    24   26J.Troll    07/99  4842   Brown-3  12   26   263.修改数值域取值awk '{if($1=="M.Tansley") $5=$6-1; print $1, $6, $5, $7}' grade.txtM.Tansley 40 39 44J.Lulu 24 9 26P.Bunny 35 12 28J.Troll 26 12 26L.Tansley 30 12 284.修改文本域awk '{if($1=="J.Troll") ($1="J.Troll.L");print $1}' grade.txtM.TansleyJ.LuluP.BunnyJ.Troll.LL.Tansley5.只显示修改记录awk '{if( $1 == "J.Troll" ) {$1="J.Troll.L"; print $1}' grade.txtawk: Syntax error at line 1 of program << {if( $1 == "J.Troll" ... >> context is        {if( $1 == "J.Troll" ) {$1="J.Troll.L"; print >>>  $1} <<<        1 extra {awk: illegal statement at line 1 of program << {if( $1 == "J.Troll" ... >>错误原因:少了一个“}”结束awk '{if( $1 == "J.Troll" ) {$1="J.Troll.L"; print $1}}' grade.txtJ.Troll.L6.创建新的域awk 'BEGIN{ print "Name\t Difference"} {if($6 < $7) {$8=$7-$6; print $1,$8}}' grade.txtName     DifferenceM.Tansley 4J.Lulu 27.统计数据awk '(tot += $6); END{print "Club student total points:" tot}' grade.txtM.Tansley  05/99  48311  Green    8    40   44J.Lulu     06/99  48317  green    9    24   26P.Bunny    02/99  48     Yello    12   35   28J.Troll    07/99  4842   Brown-3  12   26   26L.Tansley  05/99  4712   Brown-2  12   30   28Club student total points:1558.文件长度相加ls -l | awk ' /^[^d]/ {print $9"\t"$5} {tot += $5}END {print "total KB:"tot}'cat     0cat_file.txt    28data.f  356delete_me_and_die       284first2  61grade.txt       235info.txt        354myfile  23test.bak        225test.sql        225who.out 1998wow     229total KB:4018查看当前目录下的所有文件:ls -ltotal 24-rw-r--r--   1 xxxx     group          0 Nov 19 10:12 cat-rw-r--r--   1 xxxx     group         28 Nov 14 20:32 cat_file.txt-rw-r--r--   1 xxxx     group        356 Nov 16 19:50 data.f-rw-r--r--   1 xxxx     group        284 Nov 19 10:36 delete_me_and_die-rwxr--r--   1 xxxx     group         61 Nov  8 09:15 first2-rw-r--r--   1 xxxx     group        235 Nov 19 10:44 grade.txt-rwxr--r--   1 xxxx     group        354 Nov 17 11:05 info.txt-rwxr-----   1 xxxx     group         23 Nov  7 19:12 myfile-rwxr--r--   1 xxxx     group        225 Nov 15 18:08 test.bak-rwxr--r--   1 xxxx     group        225 Nov 15 14:12 test.sql-rw-r--r--   1 xxxx     group       1998 Nov 15 14:15 who.out-rw-r--r--   1 xxxx     group        229 Nov 19 14:44 wow

--the end--

热点排行