Y
Y
Yaroslav Korobeinikov2020-05-16 14:07:10
linux
Yaroslav Korobeinikov, 2020-05-16 14:07:10

How to write awk rulebook to parse colored text in command output?

Let's say some command is being executed, in the output of which there are red lines (red text)
Is it possible to somehow filter this output through awk so that only these red lines are shown?

comand_with_colored_ouput | awk '/регулярка чтобы совпадала только с любым текстом красного цвета/'

I'm still at the stage of such a team
comand_with_colored_ouput | awk '/\\033\[31m(ТутЧто-тоДолжноБыть??Чего мне не хватает?)\\033\[m/'

But it does not work very well, maybe this is impossible or am I doing something wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xotkot, 2020-05-16
@haisenberg_ex

if on one line

echo -e "\033[37;1;41m Красный \033[0m\n\033[37;1;43m Желтый \033[0m\n\033[37;1;42m Зелёный \033[0m"

echo -e "\033[37;1;41m Красный \033[0m\n\033[37;1;43m Желтый \033[0m\n\033[37;1;42m Зелёный \033[0m" | awk '/\033\[37;1;41m/'

if on multiple lines
echo -e "\033[37;1;41m Крас\nный \033[0m\n\033[37;1;43m Желтый \033[0m\n\033[37;1;42m Зелёный \033[0m"

echo -e "\033[37;1;41m Крас\nный \033[0m\n\033[37;1;43m Желтый \033[0m\n\033[37;1;42m Зелёный \033[0m" | awk '/\033\[37;1;41m/,/\033\[0m/'

in general it looks like this:
behave | awk '/код начала цвета/,/код конца цвета/'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question