d******i 发帖数: 7160 | 1 在自学shell。经常发现这个getline冒出来。
可我的环境总说找不到。
感觉像是c的函数啊。在shell里用的挺多。
咋安装呢?
谢谢! |
v*s 发帖数: 29 | 2 来个具体的例子
【在 d******i 的大作中提到】 : 在自学shell。经常发现这个getline冒出来。 : 可我的环境总说找不到。 : 感觉像是c的函数啊。在shell里用的挺多。 : 咋安装呢? : 谢谢!
|
d******i 发帖数: 7160 | 3 输入重定向(getline)
getline 函数用来从标准输入,例如管道或者文件来读入数据,而不是
从正被处理的当前文件。getline 取得输入的下一行,并更新NF、NR
和FNR等内置变量的值。如果getline找到记录则返回1,达到EOF(文
件结束)则返回0。如果有错误则返回-1。
举例1:
$ nawk 'BEGIN{"date"|getline d;print d}' datafile
2005年05月06日 星期五 15时05分41秒 CST
解释:执行date命令,然后把输出从管道送到getline,并赋给自
定义变量d,然后打印d。
举例2:
$nawk 'BEGIN{while("ls"|getline) print}'
awk.sc2
datafile
datafile2
employees
employees2
lab5.data
names
passwd
解释:将把ls的输出送到getline。对于每次循环,getline都从
ls读取一个以上输出,然后打印到屏幕上
好像getline不认得,运行不了。 |
s*******e 发帖数: 326 | 4 应该是awk里的一个函数,我跑这两个例子都没问题
你的awk版本是多少,什么系统
【在 d******i 的大作中提到】 : 输入重定向(getline) : getline 函数用来从标准输入,例如管道或者文件来读入数据,而不是 : 从正被处理的当前文件。getline 取得输入的下一行,并更新NF、NR : 和FNR等内置变量的值。如果getline找到记录则返回1,达到EOF(文 : 件结束)则返回0。如果有错误则返回-1。 : : 举例1: : $ nawk 'BEGIN{"date"|getline d;print d}' datafile : 2005年05月06日 星期五 15时05分41秒 CST : 解释:执行date命令,然后把输出从管道送到getline,并赋给自
|
d******i 发帖数: 7160 | 5 我装的是gnuwin32。里面的awk版本如下。
不会连这个也是阉割版的吧?
c:\XXX>awk --version
GNU Awk 3.1.6
Copyright (C) 1989, 1991-2007 Free Software Foundation.
This program is free software; you can redistribute it and/or modi
it under the terms of the GNU General Public License as published
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
【在 s*******e 的大作中提到】 : 应该是awk里的一个函数,我跑这两个例子都没问题 : 你的awk版本是多少,什么系统
|
x****s 发帖数: 921 | 6 try cygwin
【在 d******i 的大作中提到】 : 我装的是gnuwin32。里面的awk版本如下。 : 不会连这个也是阉割版的吧? : c:\XXX>awk --version : GNU Awk 3.1.6 : Copyright (C) 1989, 1991-2007 Free Software Foundation. : This program is free software; you can redistribute it and/or modi : it under the terms of the GNU General Public License as published : the Free Software Foundation; either version 3 of the License, or : (at your option) any later version. : This program is distributed in the hope that it will be useful,
|