I have two files that I want to compare. A sorted and an unsorted one.
ex fileA (sorted)
ABA
FRE
DIR
ex fileB (unsorted)
AJGHEKSLANVJJFABAKEIFJA
OPTOEKSMKVMGKVABAALKKSK
is there a way to find which words from fileA exist in fileB?
I have two files that I want to compare. A sorted and an unsorted one.
ex fileA (sorted)
ABA
FRE
DIR
ex fileB (unsorted)
AJGHEKSLANVJJFABAKEIFJA
OPTOEKSMKVMGKVABAALKKSK
is there a way to find which words from fileA exist in fileB?
There may be tools to do it faster, but you could consume the first file in a loop and check like
while read -r pat; do
if grep -q "$pat" fileB; then
printf '%s has a match' "$pat"
fi
done < fileA
Try this :
grep -f fileB fileA
All the lines from fileA that are there in fileB would be displayed on the console.