shell - linux中如何筛选一个文件中的内容在另一个文件中出现过?
巴扎黑
巴扎黑 2017-04-17 16:18:09
0
2
700

比如a文件中有:

100
200
300

b文件中有:

This is 100.
That is 200.
Hello 400.

想取出b文件中符合条件的这两条:

This is 100.
That is 200.

单从linux文件操作的角度有好的实现方法吗?

巴扎黑
巴扎黑

reply all(2)
迷茫

Execute commandgrep -f a b即可
使用awk的话,可以这样awk 'NR==FNR{x[

];next}{for(i in x)if(🎜~i)print}' a b🎜
PHPzhong

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!