首页 > 代码库 > getline数据来源你的三种方式

getline数据来源你的三种方式

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

 

# awk ‘BEGIN {system("echo \"Input your name:\"");getline d;print "\nYour name is",d"!\n"}‘
Input your name:
berry

Your name is berry!

# awk ‘BEGIN {system(" echo \"Input your name:\\c\" ");getline d;print "\nYour name is",d"!\n"}‘
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

 

getline数据来源你的三种方式