I am trying to implement bash script that is reading from error log file and comparing strings with exceptions.
I am trying to compare it with if
error="[*] Text Text @ level 4: 'Some text' [parent = 'Not found'] "
exception="'Not found'"
if [[ "${error}" == *"${exception}"* ]]; then
echo "Yes it contains!"
fi
In this case I would expect the script to return "Yes it contains!", but it doesn't work as I expected. But it is true that my logs contain special character as well, anyone knows how should I handle that and compare it?
For me my if also works, but I might have something wrong in my nested loop. I am running the script in following process.
I have file with errors called
mylogfile.txt:[*] Text Text @ level 4: 'Some text' [parent = 'Not found']Then I have another file where I have exceptions inserted
exception.txt:'Not found'I do a loop over both files to see if I find anything:
while IFS='' read -r line || [ -n "$line" ]; do exception="$line" while IFS='' read -r line || [ -n "$line" ]; do err="$line" if [[ "${err}" == *"${exception}"* ]]; then echo "Yes it contains!" fi done < "mylogfile.txt" done < "exception.txt"
xxdto show the special characters.