I want to use grep
in a bash script to find the corresponding lines in the file, highlight the color matches, and then print the results in the table using the column
command, Something like this:
data=`cat file.data | egrep -i --color "$search"` echo $'\n'"col1"$'\t'"col2"$'\t'"col3"$'\t'"col4"$'\n'"$data" | column -t -s$'\t'
The above code does everything as desired, except that the color is lost.
Here is a simplified example:

As you can see, when I used grep
, the results were printed on separate lines and in color, but when I save the results in a variable and then print the variable, the line breaks and the colors disappear.
Is there any way to do what I ask?
source share