Create Dynamic If condition
Hi,
I have a file color.txt which has data as shown below
Red
Blue
Green
Yellow
White
Pink
Black
Based on a variable I execute a tail command as shown below
tail -${LEFT_OVR} color.txt
LEFT_OVR can be any number less than count of number of lines in a file
so if LEFT_OVR=2, then output would be
Pink
Black
Based on output of tail command I need to build a dynamic If condition, which will look something like this
if [ "$color" = "Pink" ] || [ "$color" = "Black" ]
I'm planning to do something like this
tail -${LEFT_OVR} color.txt > tail_out
one_line=`awk 'BEGIN { ORS = " " } { print }' tail_out`
COND=""
for c in $one_line
do
COND="[ color = $c ] $COND"
done
Next I would check for occurrence of ] [ and replace with ] || [
Any ideas if there is something easier to achieve similar result?