Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to diff top lines of two files without intermediate file

Tags:

linux

bash

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 :

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.log interpreted as a file. But I don't remember how. Maybe it was another shell...
Thank you.

like image 570
Tom97531 Avatar asked Aug 19 '11 15:08

Tom97531


People also ask

Which command gives all differences between two files?

diff stands for difference. This command is used to display the differences in the files by comparing the files line by line.

Which command is used to find similar lines in two files?

A. Use comm command; it compare two sorted files line by line.


1 Answers

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

 diff <(head -n 2000 file1.log) <(head -n 2000 file2.log) 
like image 131
Mark Longair Avatar answered Oct 09 '22 05:10

Mark Longair