awk :: 使用不区分大小写的方式在 2 个文件中查找常用词
awk :: use case insensitive to find common words in 2 files
我有两个文件 1.txt
和 2.txt
。
在1.txt
中我们可以找到这些词:
apple
orange
butter
flower
在2.txt
中我们可以找到这些词:
dog
cat
Butter
tower
我可以使用命令
awk 'NR==FNR{a[[=16=]];next} ([=16=] in a)' 1.txt 2.txt
找到两个文件中的共同行,但 Butter
或 butter
一词未被 return 编辑,因为它在两个文件之一中有一个大写字母。
如何returnbutter
或Butter
?
我只想找到共同点
使用 grep
更容易
$ grep -iwFf file1 file2
Butter
或与awk
$ awk 'NR==FNR{a[tolower([=11=])]; next} tolower([=11=]) in a' file1 file2
Butter
我有两个文件 1.txt
和 2.txt
。
在1.txt
中我们可以找到这些词:
apple
orange
butter
flower
在2.txt
中我们可以找到这些词:
dog
cat
Butter
tower
我可以使用命令
awk 'NR==FNR{a[[=16=]];next} ([=16=] in a)' 1.txt 2.txt
找到两个文件中的共同行,但 Butter
或 butter
一词未被 return 编辑,因为它在两个文件之一中有一个大写字母。
如何returnbutter
或Butter
?
我只想找到共同点
使用 grep
$ grep -iwFf file1 file2
Butter
或与awk
$ awk 'NR==FNR{a[tolower([=11=])]; next} tolower([=11=]) in a' file1 file2
Butter