script to return records which are not matching

file1

abcd
efgh
ijkl
mnop

file2

mnop
qrst
uvwx
xyza

file3

1234
4567
7890

searchRecords

abcd
azyx
4567
aaaa

file1, file2, file3 aret the source files. I want to search the records in the file searchRecords. The records which are not present in source files should be my output.
With the above example, expected output is
output

azyx
aaaa

what you have tried so far ..

If I've understood your logic, you want to find records in file searchRecords that are not in any of file, file2 or file3

You can acheive this like this:-

sort -u file1 file2 file3 > mergedfile
grep -vf mergedfile searchRecords

This will merge all the first three files (removing duplicates) and then find all records in searchRecords which are not in the combined file mergedfile.

I hooe that this helps, but if I have the logic wrong, please correct me.

Robin
Liverpool/Blackburn
UK

yes you have understood my problem well.... But below error is coming up when trying the command

bash-3.00$ grep -vf MergedFile searchRecords
 
 
grep: illegal option -- f
Usage: grep -hblcnsviw pattern file . . .

Oh, I forgot that the options may be OS specific. Have a read of the man page for fgrep instead. Perhaps you just need:-

sort -u file1 file2 file3 > mergedfile
fgrep -v mergedfile searchRecords

.... instead.

Good luck!

Robin
Liverpool/Blackburn
UK

I tried the above commands and get below output

$ sort -u file1 file2 file3 > mergedfile
$ fgrep -v mergedfile searchRecords
abcd
azyx
4567
aaaa

but the expected output is

azyx
aaaa

:confused:

Use -f option in fgrep

$ fgrep -vf mergedfile searchRecords
azyx
aaaa
$

:b: - This worked. Thanks a lot

As you can tell, I didn't read the man page for fgrep either. Sorry about that. Is everything working as required now?

Robin
Liverpool/Blackburn
UK