I have 2
files File1, and File2
. File1
is list of strings
, line1 contain string1
, line2 contains strings2 and so on
. I would like to pick string1
from File1
and compare it with File 2
. Then I pick string2
and compare it with File2
. The script does not know how many strings are there in File1 and Fil2
. Once all the strings from File1 are compared with File2,
the script should give an alarm/pop up window
with the list of strings
matched in File2
.
CodePudding user response:
I don't understand what you mean by popup/window. Also it will be better to use something like grep. Based on the requirement, this is what I came up with.
// abc.txt
abcd
ab
cd
abc
// def.txt
dfd
abc
ab
abcd
file1=()
file2=()
filename1="abc.txt"
filename2="def.txt"
while read -r line; do
name="$line"
file1 =("$name")
done < "$filename1"
while read -r line; do
name="$line"
file2 =("$name")
done < "$filename2"
for i in "${file2[@]}"
do
for j in "${file1[@]}"
do
if [ "$i" = "$j" ]; then
echo "Match found $i"
break
fi
done
done