I have one array item1 with entries like
item1=($(cat abc.txt | grep "exam" |sed 's/.*exam//'|sed 's/^ *//g'|cut -d/ -f2))
so in this array i have below entries
abc.raml def.raml xyz.schema check1.json check2.json
now i want check for each item of this array item1, if it is present in another array item2
so i did this using for loop
for i in "${item1[@]}"; do
for j in "${item2[@]}"; do
if [[ $i == $j ]]
then
echo "file $i present in both arrays"
fi
done
done
so this loop is working fine.. but can we just get a one liner command to check if a particular element is present in another array without using another for loop inside
i tried this but it is not working
for i in "${item1[@]}"; do
echo ` "${item2[@]}" | grep "$i" `
if echo $? == 0
then
echo "file $i present in both arrays"
fi
done
done
Please help me here