查找文本文件的差集
【问题】
I have a pattern file and another text file. I want to see what are the patterns in the pattern file which are missing in the text file. The whole lines in the pattern file will do. Any bash/grep/awk solutions?
while read config_opt
do
if ! grep $config_opt $your_text_file > /dev/null 2>&1; then
echo -e $config_opt;
fi
done < $your_pattern_file
【回答】
上面提到的算法是找出“pattern file”和“another text file”的“差集”,用 grep 可以做到,但太慢了。可以试试集算器,不仅可以实现更丰富的算法,性能也会好很多。代码如下:
A |
|
1 |
=file("E:\\\file1.txt").cursor() |
2 |
=file("E:\\\file2.txt").cursor() |
3 |
=[A1.sortx(_1),A2.sortx(_1)].mergex@xd(_1) |
4 |
=file("E:\\result.txt").export(A3) |