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
阅读(1680) | 评论(0) | 转发(0) |