Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

command to get common lines from two files 1

Status
Not open for further replies.

tech123786

Technical User
Nov 13, 2006
31
US
Hello,
This is a general unix question. I have two files in which they have some 300 server names listed line by line . Some of the lines are common in both the files. I need to get these names which are similar in both the files.Is there any command or utility to get these lines?
I know I can use cmp or diff to compare the files for the differences. But I need to get the common names in both the files.
Thanks
 

check out man page for comm command

comm -12 file1 file2

but both files need to be sorted

if not sorted, then:

sort -o file1.sorted file1
sort -o file2.sorted file2
comm -12 file1.sorted file2.sorted

HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top