![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pattern matching in file and then display 10 lines above every time | namishtiwari | Shell Programming and Scripting | 16 | 10-20-2008 07:50 PM |
| pattern matching over more lines | trek | Shell Programming and Scripting | 3 | 04-22-2008 03:37 AM |
| Reading lines in a file matching a pattern | torenji | Shell Programming and Scripting | 4 | 10-25-2007 01:15 AM |
| Returning filename and matching lines | smb_uk | Shell Programming and Scripting | 2 | 10-05-2007 03:08 PM |
| grep something to find which files, lines contain something | yls177 | UNIX for Dummies Questions & Answers | 4 | 11-26-2002 09:15 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Find matching lines between 2 files
How do I find matching lines between two files?
|
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
grep -f File1 File2 |
|
#3
|
|||
|
|||
|
Quote:
this grep -f will kill time like anything.... consider this custom perl tool, Code:
#! /opt/third-party/bin/perl
$i = 1;
open(fh, "small") || die "unable to open the file <small>";
while( chomp($content = <fh>) )
{
$fileHash{$content} = $i;
$i += 1;
}
close(fh);
open(file, "big") || die "Unable to open the file <big>";
while ( chomp($rec = <file>) ) {
print "\nMatch:$rec" if exists $fileHash{$rec} ;
}
close(file);
exit 0
|
|
#4
|
|||
|
|||
|
comm is meant to find lines matching/not matching between files.
if the files are sorted: Code:
comm -12 file file2 Code:
sort -o tmpfile2 file2 sort -o tmpfile1 file1 comm -12 tmpfile1 tmpfile2 |
|
#5
|
|||
|
|||
|
What & why is the -12 used?
|
|
#6
|
|||
|
|||
|
I got the comm to work. I used the man comm to find out -12. Thanks a bunch!
|
|||
| Google The UNIX and Linux Forums |