grep -offile1 file2 | sort | uniq -c
2 god
1 pod
2 rod
--- Post updated at 16:24 ---
Hoppla - didn't take your thread title into account. Try this awk :
awk '
FNR==NR {OUT[NR] = $1
CNT[$1]
MX = NR
next
}
{for (c in CNT) if (match ($0, c)) CNT[c]++
}
END {for (i=1; i<=MX; i++) print OUT, CNT[OUT]
}
' file[12]
god 2
god 2
pod 1
rod 2
Thanks,
i think this works.testing it for a big file.
just one thing.
i am trying to put the codes in a .awk file and then run it.
i would like to run it like
Put the part between but excluding the single quotes into a file, name it to taste, and run it as you posted. file[12] will be expanded b the shell to file1 file2 .