awk ARGIND

ARGC        The number of command line arguments (does not include
                   options to gawk, or the program source).   命令行参数的个数
ARGIND
     The index in ARGV of the current file being processed. 命令行中文件序号
ARGV
        Array of command line arguments. The array is indexed
                   from 0 to ARGC - 1. Dynamically changing the contents
                   of ARGV can control the files used for data. 命令行参数数组
大体类似于C语言 int main(int argc,char *argv[])

我要比较a和b两个文件; 
a              b

1              1

qw            2

qq            d

123          cd
我怎么才能列出b文件中完全不包含a文件的行??


解答: awk 'ARGIND==1 {a[$0]} ARGIND>1&&!($0 in a) {print $0}' a b
   
或者:
awk 'NR==FNR {a[$0]} NR>FNR&&!($0 in a) {print $0}' a b

代码解释:
ARGIND==1{a[$0]}
#ARGIND==1 判断是否正在处理第一个文件,本例为文件a
# {a[$0]} 初始化(或叫做定义)a[$0]
ARGIND>1&&!($0 in a){print $0}
#ARGIND>1 判断是否在处理第二个或第n个文件,本例只有一个文件b
#并且判断a[$0]是否未定义,然后打印$0

你可能感兴趣的:(c,command,File,语言,include)