84669 personnes étudient
152542 personnes étudient
20005 personnes étudient
5487 personnes étudient
7821 personnes étudient
359900 personnes étudient
3350 personnes étudient
180660 personnes étudient
48569 personnes étudient
18603 personnes étudient
40936 personnes étudient
1549 personnes étudient
1183 personnes étudient
32909 personnes étudient
比如a文件中有:
100 200 300
b文件中有:
This is 100. That is 200. Hello 400.
想取出b文件中符合条件的这两条:
This is 100. That is 200.
单从linux文件操作的角度有好的实现方法吗?
执行命令grep -f a b即可使用awk的话,可以这样awk 'NR==FNR{x[$0];next}{for(i in x)if($0~i)print}' a b
grep -f a b
awk 'NR==FNR{x[$0];next}{for(i in x)if($0~i)print}' a b
如果说是比较两个文件中相同的数据的话,可以使用comm命令。如果说需要找出包含某些数据的行的话,还是要先把A文件中的数据提取出来,例如A是100,200,300,那么我们可以用egrep '[1-3]00' b,这样结果就出来了。但是涉及到一些比较复杂文件对比,还是建议使用shell或awk、python来处理。
执行命令
grep -f a b
即可使用awk的话,可以这样
awk 'NR==FNR{x[$0];next}{for(i in x)if($0~i)print}' a b
如果说是比较两个文件中相同的数据的话,可以使用comm命令。
如果说需要找出包含某些数据的行的话,还是要先把A文件中的数据提取出来,例如A是100,200,300,那么我们可以用egrep '[1-3]00' b,这样结果就出来了。
但是涉及到一些比较复杂文件对比,还是建议使用shell或awk、python来处理。