文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>awk函数 getline system(个人笔记)

awk函数 getline system(个人笔记)

时间:2008-09-19  来源:ubuntuer

 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

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载