Searching across multiple files if pattern is available in all files searched

I have a list of pattern in a file, I want each of these pattern been searched from 4 files. I was wondering this can be done in SED / AWK.

say my 4 files to be searched are

> cat f1

abc/x(12) 1  
abc/x     3 
cde       2  
zzz       3  
fdf       4

> cat f2
fdf 4 
cde 3 
abc 2 
zzz 1 

> cat f3
cde 3  
abc 2  
fdf 1  
zzz 4  

> cat f4
zzz 3
fdf 4
abc 1
cde 2
I have file which has pattern to be search in all these 4 files. I want the output only when the search pattern is available in all the 4 files. Also I would like to have file written out patterns which is not present in all 4 files.
> cat input_pattern_file
cde
fdf
abc
zzz

Thanks.

so what have you tried?

I tried ... It doesn't seem to work

#!/bin/csh
foreach x ( `cat input_pattern_file` )
sed -n '/${x}/p' f1 >> out
# grep -w "$x" f1 
end

Thanks.

awk 'NR==FNR{a[$1];next} $1 in a {c[$1]++}
     END{for ( i in c) if (c==4) print i}' input_pattern_file f1 f2 f3 f4 > available_pattern
grep -v -f available_pattern input_pattern_file > non_pattern

In the example input files I have mentioned we have "zzz" in all files, but with the given awk it is not getting printed out. Also I would need to print the values of 2nd column for the matching inputs from each of the 4 files.

> awk 'NR==FNR{a[$1];next} $1 in a {c[$1]++}  END {for ( i in c) if (c==4) print i}' list f1 f2 f3 f4
cde
fdf

Thanks.

I still get zzz line.

awk 'NR==FNR{a[$1];next} $1 in a {c[$1]++}
     END{for ( i in c) if (c==4) print i}' input_pattern_file f1 f2 f3 f4

cde
zzz
fdf

if you need 2nd column, add one more command

grep -f available_pattern f1 f2 f3 f4

I can see it working ...

Is there a way I can publish missing cases from each of the file using the existing awk

Also do we have "SED" equivalent of "grep -f" as I need to process few millions of lines and SED is really quick against grep.

Thanks.