比如a文件中有:
100
200
300
b文件中有:
This is 100.
That is 200.
Hello 400.
想取出b文件中符合条件的这两条:
This is 100.
That is 200.
单从linux文件操作的角度有好的实现方法吗?
迷茫2017-04-17 16:20:09
Execute commandgrep -f a b
即可
使用awk的话,可以这样awk 'NR==FNR{x[
PHPz2017-04-17 16:20:09
If you want to compare the same data in two files, you can use the comm command.
If you need to find the rows containing certain data, you still need to extract the data in file A first. For example, A is 100, 200, 300, then we can use egrep '[1-3]00' b, This is how the results came out.
But when it comes to some more complex file comparisons, it is recommended to use shell, awk, or python to handle it.