Grep doesn't work when assigning to variable

Hello,

First of all, I'd like to say hello to all members of forum.
Can You please help me with the matter described below?
I am trying to fetch a data from the file to variable, I am doing this using below script:

returned=`tail -50 SapLogs.log | grep -i -E "Error|"`
echo $returned

Unfortunately, the $returned variable contains all 50 lines from SapLogs file. There is no filtering by "Error". Moreover, when I am executing tail -50 SapLogs.log | grep -i -E "Error| without assigning to variable, it works perfectly.

What am I doing wrong? It could be very stupid mistake, but I am new in Bash scripting, please help.

Regards,
Adrian

You have used -E which enables ERE within grep. | means OR . And providing nothing after pipe means Null.

Are you sure you are executing same command (when works)?
If you want to search just Error (case-insensitive search ) you dont need pipe.

returned=`tail -50 SapLogs.log | grep -i "Error"`

If you want search Error|

returned=`tail -50 SapLogs.log | grep -i "Error|"`

Hello,

Thank You a lot! It works now. But.. I have another problem now. I'll post new topic. Please look there if You have a moment.

Regards,
Adrian Jdrzejewski