getline数据来源你的三种方式

(1)getline从交互式的用户输入中c中获取内容;

# awk 'BEGIN {system("echo "Input your name:"");getline d;print "
Your name is",d"!
"}'
Input your name:
berry

Your name is berry!

# awk 'BEGIN {system(" echo "Input your name:\c" ");getline d;print "
Your name is",d"!
"}'
Input your name:berry

Your name is berry!

(2)getline从文件中获取内容;

# awk -F":" 'BEGIN{while(getline < "/etc/passwd" >0){if($1~"sy"){print $1}}}'
sys
sync
syslog

(3)从命令输出中获取;

# awk 'BEGIN{"date" | getline d; print d}'
Sun Jan  1 22:37:50 CST 2017
原文地址:https://www.cnblogs.com/Berryxiong/p/6241707.html