Compare multiple files, and extract items that are common to ALL files only

I have this code

awk 'NR==FNR{a[$1]=$1;next} a[$1]' file1 file2

which does what I need it to do, but for only two files. I want to make it so that I can have multiple files (for example 30) and the code will return only the items that are in every single one of those files and ignore the ones that are not.

For simplicity of a big example, say I have 30 files, and all of them have the words "one, two, three, four, five" but 10 of them have additional words of "six, seven, eight, nine, ten". I want the output of my code to be

output:

one
two
three
four
five

try:

awk '
!f[FILENAME] {for (i in t) if (!a) delete t ; delete a; f[FILENAME]=FILENAME}
NR==FNR {t[$0]=$0}
{a[$0]=$0}
END { for (i in t) if (!a) delete t; for (i in t) print i}
' file*
1 Like

I tried following the code along, but I couldn't understand it or get it to work. Can you update it using these files as an example please?

file1:
one
two
three
file2:
one
two
three
file3:
one
two
three
four
file4:
one
three
five
file5:
one
three
six
eight
output:
one
three

Maybe awk version does not support delete . try:

awk '
!f[FILENAME] {for (i in t) if (!a) {t=""} ;
   for (i in a) a="";
   f[FILENAME]=FILENAME
}
NR==FNR {t[$0]=$0}
{a[$0]=$0}
END { for (i in t) if (!a) t=""; for (i in t) {if (t) print i}}
' file*
1 Like

not all awk's support the delete array paradigm.
the workaround is: split("",array)

I'm sorry but I still cannot get it to work, would you be able to use my filenames in the example given? I am having trouble with the filename part

Do you mean built-in variable FILENAME ? What is the error?

ahh, i see. I thought FILENAME was my file, thanks for clarifying