系统提供了两个待处理文件a.txt
和b.txt
,其中文件 a.txt
中的部份内容以下:shell
HelloMy Name is AliceWhat is your nameI am BobI came from ChinaWhere are you fromOh my God
文件 b.txt
中的部份内容以下:数组
Alice is a good boyBob is a nice man and he is one of my best friendGod bless you
将文件 a.txt
中每一行的最后一个单词做为集合 1
;将文件 b.txt
中每一行的第一个单词做为集合 2
;请使用 shell
语言编写程序,输出包含在集合 1
但不包含在集合 2
的全部元素。less
禁止使用echo
手动输出或相似的方法手动输出差集。spa
# NR==FNR 第一个参数b.txt # set[$1] 以第一列单词为索引的数组 # !(NR==FNR) 不是第一个参数b.txt 也就是a.txt # $NF in set 最后一列单词包含在数组中 awk ' {if (NR==FNR) set[$1] = $1} {if(!(NR==FNR) && !($NF in set)) {print $NF}} ' b.txt a.txt
Hello
name
China
from