Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4756397
  • 博文数量: 930
  • 博客积分: 12070
  • 博客等级: 上将
  • 技术积分: 11448
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 16:57
文章分类

全部博文(930)

文章存档

2011年(60)

2010年(220)

2009年(371)

2008年(279)

分类:

2008-09-19 21:19:00

 getline:
    BEGIN { printf "Enter your name: "
        getline name < "-"
        print name
    }
  从stdin中读取name.
zj@zj:~/Script/blog_script$ awk 'BEGIN{ printf "Enter your name:";getline name < "-";print name}'
Enter your name:zj
zj

     awk的BEGIN是在文本读取之前处理的所有不需要文本,END是在文本读取结束之后进行的

    while ( (getline < "data") > 0 )
        print
从数据中读取.

    name = getline //name赋于的是getline的返回值(1,0,-1)
    The getline function is similar to awk's next statement. While both cause the next input line to be
    read, the next statement passes control back to the top of the script. The getline function gets the
    next line without changing control in the script. Possible return values are:
         1 If it was able to read a line.
         0 If it encounters the end-of-file.
         -1 If it encounters an error.

系统调用:
    zj@zj:~/Script/cushell/08.09.19$ awk 'BEGIN { while("ls" | getline name)print name}'
    question1
    test1

    zj@zj:~/Script/cushell/08.09.19$ awk 'BEGIN {system("ls")}'
    question1  test1

函数调用:
     awk 'function upper(STRING){str=toupper(substr(STRING,1,1))substr(STRING,2);return str};{$1=upper($1);print $0}' name
    


zj@zj:~/Script/blog_script$ awk 'function upper(STRING){str=toupper(substr(STRING,1,1))substr(STRING,2);return str};{$1=upper($1);print $0}' name
Zj 123
Ubuntu 456
Debian 789

阅读(1638) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~