awk+system+getline
2016-10-06 22:26
232 查看
# gawk '{cmd="ls";system(cmd)}' argFile
argFile argOne
argFile argOne
argFile argOne
argFile argOne
(1)awk中使用system执行复杂的SHELL命令。
# gawk '{cmd="ls";system(cmd)}' argFile
argFile argOne
argFile argOne
argFile argOne
argFile argOne
(2)awk中用双引号把命令括起来,然后用getline获取命令执行的结果。
#gawk '{ "ifconfig -a "| getline M; print M; }' argFile
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
inet 127.0.0.1 netmask ff000000
net0: flags=100001100843<UP,BROADCAST,RUNNING,MULTICAST,ROUTER,IPv4,PHYSRUNNING> mtu 1500 index 4
inet 10.134.9.30 netmask ffffff00 broadcast 10.134.9.255
由于argFile只有四行,因此只输出了四行。getline不能获取到system执行命令之后的结果。
(3)在awk中也可以跟执行shell命令一样调用SHELL脚本。
# cat argFile
1 a b c
1 a b c
1 a b c
1 a b c
# cat printOne
#! /bin/ksh
print "NO:$1"
# gawk '{cmd="./printOne "$1; cmd | getline result; sub($1,result);print } ' argFile
NO:1 a b c
NO:1 a b c
NO:1 a b c
NO:1 a b c
# gawk '{"./printOne "$1 | getline result; sub($1,result);print } ' argFile
NO:1 a b c
NO:1 a b c
NO:1 a b c
NO:1 a b c
argFile argOne
argFile argOne
argFile argOne
argFile argOne
(1)awk中使用system执行复杂的SHELL命令。
# gawk '{cmd="ls";system(cmd)}' argFile
argFile argOne
argFile argOne
argFile argOne
argFile argOne
(2)awk中用双引号把命令括起来,然后用getline获取命令执行的结果。
#gawk '{ "ifconfig -a "| getline M; print M; }' argFile
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
inet 127.0.0.1 netmask ff000000
net0: flags=100001100843<UP,BROADCAST,RUNNING,MULTICAST,ROUTER,IPv4,PHYSRUNNING> mtu 1500 index 4
inet 10.134.9.30 netmask ffffff00 broadcast 10.134.9.255
由于argFile只有四行,因此只输出了四行。getline不能获取到system执行命令之后的结果。
(3)在awk中也可以跟执行shell命令一样调用SHELL脚本。
# cat argFile
1 a b c
1 a b c
1 a b c
1 a b c
# cat printOne
#! /bin/ksh
print "NO:$1"
# gawk '{cmd="./printOne "$1; cmd | getline result; sub($1,result);print } ' argFile
NO:1 a b c
NO:1 a b c
NO:1 a b c
NO:1 a b c
# gawk '{"./printOne "$1 | getline result; sub($1,result);print } ' argFile
NO:1 a b c
NO:1 a b c
NO:1 a b c
NO:1 a b c
相关文章推荐
- awk调用shell命令 getline system
- awk(3)-awk getline
- awk getline
- GetSystemIcon.cs
- 通过System.getProperties()获取系统参数
- C++中cin.get(),cin.getline(),cin>>,gets(),cin.clear()使用总结
- system setting manager, save or get system values from database
- Textview的getLineCount返回0
- VC get system time
- Android:Eclipse-unable to get system library for the project
- android系统getSystemService原理分析
- java System.getProterty()的使用
- C++中cin、cin.get()、cin.getline()、getline()、gets()等函数的用法
- LINQ to Entities 不识别方法 System.String get_Item(System.String)
- Android中的getSystemservice,很全
- GetSystemMetrics
- C++中cin、cin.get()、cin.getline()、getline()、gets()等函数的用法
- GetSystemMetrics () 获得系统配置信息
- in<<, cin.get,cin.getline等函数深入分析
- getSystemService