84669 Lernen von Personen
152542 Lernen von Personen
20005 Lernen von Personen
5487 Lernen von Personen
7821 Lernen von Personen
359900 Lernen von Personen
3350 Lernen von Personen
180660 Lernen von Personen
48569 Lernen von Personen
18603 Lernen von Personen
40936 Lernen von Personen
1549 Lernen von Personen
1183 Lernen von Personen
32909 Lernen von Personen
比如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来处理。