博客首页 注册 建议与交流 排行榜 加入友情链接         宝宝相册的专门空间
推荐 投诉 搜索: 帮助

h0ng123 linux,oracle.unix

---在蓝天白云下自由飞翔 爱生活,爱CU---
Google


学习shell脚本编程的好地方
   h0ng123.cublog.cn
关于作者  
姓名:h0ng
职业:计算机
年龄:24
位置:广东
个性介绍:学习网络技术,UNIX/linux 系统管理.娱乐


我的分类  




6.5. awk Commands from Within a File

6.5. awk Commands from Within a File

If awk commands are placed in a file, the –f option is used with the name of the awk file, followed by the name of the input file to be processed. A record is read into awk's buffer and each of the commands in the awk file is tested and executed for that record. After awk has finished with the first record, it is discarded and the next record is read into the buffer, and so on. If an action is not controlled by a pattern, the default behavior is to print the entire record. If a pattern does not have an action associated with it, the default is to print the record where the pattern matches an input line.

Example 6.10.
(The Database)

   $1        $2         $3       $4          $5

   Tom       Jones      4424     5/12/66     543354

   Mary      Adams      5346     11/4/63     28765

   Sally     Chang      1654     7/22/54     650000

   Billy     Black      1683     9/23/44     336500



   % cat awkfile

1  /^Mary/{print "Hello Mary!"}

2  {print $1, $2, $3}



   % nawk –f awkfile employees

   Tom Jones 4424

   Hello Mary!

   Mary Adams 5346

   Sally Chang 1654

   Billy Black 1683


EXPLANATION

  1. If the record begins with the regular expression Mary, the string Hello Mary! is printed. The action is controlled by the pattern preceding it. Fields are separated by whitespace.

  2. The first, second, and third field of each record are printed. The action occurs for each line because there is not a pattern controlling the action.

 原文地址 about:blank
 发表于: 2006-11-28,修改于: 2006-11-28 20:05 已浏览899次,有评论0条 推荐 投诉

  网友评论

  发表评论



Copyright © 2001-2006 ChinaUnix.net All Rights Reserved

感谢所有关心和支持过ChinaUnix的朋友们
页面生成时间:0.81362

京ICP证041476号