首页 > gawk程序中如何读取输入文件

gawk程序中如何读取输入文件

gawk可以在命令行上指定输入文件,比如gawk '/AAA/' in1.txt in2.txt
gawk也可以在程序中指定输出文件,比如gawk 'END { print 1 > "out1.txt" }'

那么,是否可以在程序中指定输入文件呢?
我想实现类似gawk '/AAA/ < "in1" { print $1 }'的功能。


FILENAME

The name of the file that awk is currently reading. When no data files are listed on the command line, awk reads from the standard input and FILENAME is set to "-". FILENAME is changed each time a new file is read (see Reading Files). Inside a BEGIN rule, the value of FILENAME is "", since there are no input files being processed yet.1 (d.c.) Note, though, that using getline (see Getline) inside a BEGIN rule can give FILENAME a value.

http://www.gnu.org/software/gawk/manual/html_node/Auto_002dset.html

【热门文章】
【热门文章】