bash 如何在没有中间文件的情况下区分两个文件的顶行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7124004/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 00:37:23  来源:igfitidea点击:

How to diff top lines of two files without intermediate file

linuxbash

提问by Tom97531

I have 2 big files and I want to make a diff between the top lines of each files, but i don't want to use intermediate files. I would like to do something like that :

我有 2 个大文件,我想在每个文件的顶行之间进行区分,但我不想使用中间文件。我想做这样的事情:

diff `head -n 2000 file1.log` `head -n 2000 file2.log`

I remember I've done something like that a long time ago, ie. make a command like head -n 2000 file1.loginterpreted as a file. But I don't remember how. Maybe it was another shell...
Thank you.

我记得很久以前我做过类似的事情,即。使命令像head -n 2000 file1.log解释为文件。但我不记得如何。也许它是另一个外壳...
谢谢。

回答by Mark Longair

You're probably thinking of process substitutionin bash. For example, try:

您可能正在考虑bash 中的进程替换。例如,尝试:

 diff <(head -n 2000 file1.log) <(head -n 2000 file2.log)