I have need to grep an entire directory for a string, and I get about 50 results. I would like to colour each second line, either text colour or background colour. Best would be a script that I can pipe the output of any command to, and so that it spits out the same (albeit coloured) output.
Not very pretty but does the trick:
(save this to foo.bash
and do grep whatever wherever | ./foo.bash
)
#!/bin/bash
while read line
do
echo -e "\e[1;31m$line"
read line
echo -e "\e[1;32m$line"
done
echo -en "\e[0m"
Here you can find the list of color codes in bash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With