I'm not sure what is going on for you. Try two separate grep actions (Linux example).
Ex: grep -o shows ONLY the matching text nothing else on the line
You are looking for 10-JUL in a bunch of logfiles, then you want specific error code
ERR 1901a
grep -f '10-JUL' logfiles*| grep -o 'ERR 1901a'
If you supply us an exact example of your problem we can help you apply this concept, otherwise this is about as good as I can do with what I have. An OS name and a shell name would help improve our answers immensely.
By default, color is added / applied to screen output, not when writing to files or pipes, so additional measures need to be taken. With some more detail info (sample data) on the problem, sensible proposals might be givven.
Just for reference, here is a little shell script that I sometimes use to check whats available if I want to use colo(u)r.
#!/bin/bash
##################################################################################
#
# Test script to show the available colours on a monitor, this allows the generation
# of highlighted output from ordinary shell scripts - to be integrated with the
# logger shell to make pretty output.
#
##################################################################################
T='XXX' # The test text
echo -e "\n 40m 41m 42m 43m\
44m 45m 46m 47m";
for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \
'1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \
' 36m' '1;36m' ' 37m' '1;37m';
do FG=${FGs// /}
echo -en " $FGs \033[$FG $T "
for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
do echo -en "$EINS \033[$FG\033[$BG $T \033[0m";
done
echo;
done
In addition to post 6, I've always noticed this and have to add an extra grep to the end of lines pipe connected sequences (probably badly written :o) to get the output I want highlighted. I usually use use an expression that matches every line too, so in your case I would append the following:-
........ | egrep --color -Ei "|abcd"
... so I'm matching your string abcd or a null (every line, but no character) to get all the output and colour the important characters.
You might be able to remove your existing grep -Ei 'abcd' and just use the above at the end, but it depends if that might leave too many records to be processed by your tr. By 'too many', I'm thinking of over 100,000 unneeded records, such a volume that might slow your overall pipeline.