I am modifying the text following tail -f.
I have the following program that monitors a file:
tail -vf -c5 /tmp/index \
| cat -n \
| sed s/^[^0-9]*\\\([0-9]\\\)/__\\\1__/g - \
;
The sed successfully changes tail's output.
From another terminal i can now do:
RED='\033[0;31m';
NC='\033[0m';
printf "I ${RED}love${NC} Stack Overflow\n" 1>>/tmp/index;
And the tail monitoring program will display the update, in color.
But what I want, is the sed program, to add by itself, colors to the output. I have tried a bunch of different setups but to no avail. Mostly involving adding backward slashes here and there.
How do I have the tail-sed program, add colors to the output?
___
, is that right?) and then what color you want to add. Do you want to color those numbers? By the way, you can simplify yoursed
tosed 's/^[^0-9]*\([0-9]\)/__\1__/
, no need for so many escapes if you quote, and theg
is pointless with anchored regex (^
), or evensed -E 's/^[^0-9]*([0-9])/__\1__/
if yoursed
has-E
. – terdon Nov 22 '23 at 17:45