# Comparing two files



## abdelilah (Apr 17, 2011)

Hello everyone

Can you please tell me how can I compare two files in Unix I know that I must use diff or cmp but it is for a specific use, I want to compare only the 10 first lines of those two files, thanks in advance.

Ps : I know it is a dumb and weird question :e.


----------



## hedwards (Apr 17, 2011)

What type of comparison are you wanting? You can use head to select the first 10 lines without too much trouble and then just compare the results between the two. Easiest way would be to take the results of that and just put them in temporary files to compare. But I do know that there are more sophisticated ways of doing it, if more complicated to actually do.


----------



## abdelilah (Apr 17, 2011)

Thank you for you answer, I just want to compare but with a single command, I don't know if it is possible to mix diff or cmp with the head command, may someone give me the command to use, thanks in advance.


----------



## mamalos (Apr 17, 2011)

As hedwards said:

`$ head -10 file1 > 10_lines_file1 && head -10 file2 > 10_lines_file2 && diff 10_lines_file1 10_lines_file2`

After your comparison you might want to delete the temporary files using *rm*.


----------



## miniqq (Apr 18, 2011)

Hi, you can try :

```
diff <(sed -n '1,10p' file1) <(sed -n '1,10p' file2)
```


```
sed -n '1,10p'
```
 will get the first 10 lines .


----------



## abdelilah (Apr 18, 2011)

Thank you all of you :e


----------

