5
votes
2answers
103 views

How would I add a prefix to input I receive from a pipe via awk and color the prefix conditionally?

Is there a way to add a prefix to lines received (and filtered) via awk - yes I know that's possible so far - and then conditionally (e.g. based on the existence of the $PS1 variable of the ...
2
votes
3answers
204 views

How can I tell echo/printf in Bash to swallow escape codes, based on a condition?

I have a Bash script that is being run interactively and as a cron job. When run interactively it outputs colored text on the terminal. However, when run in cron it doesn't have a terminal and ...
6
votes
3answers
457 views

“Friendly” terminal color names in shell scripts?

I'm aware of libraries in languages such as Ruby and Javascript to make colorizing your terminal scripts easier by using color names like "red". But is there something like this for shell scripts in ...
1
vote
3answers
87 views

How can i check for existence of color in my linux box?

I want to do something like this in my linux box: if [[ colors exist ]];then echo "some text in colors" fi my doubt is : i am using sed to put colors in log file for some text but if the linux box ...
2
votes
1answer
79 views

How do I change the colour of all lines to red begining with a % symbol?

When I use sed -i "s,.*%.*,$(tput setaf 1)&$(tput sgr0),g" A.log the whole line vanishes and when I use sed -i "s,^%.*,$(tput setaf 1)&$(tput sgr0),g" A.log only the first character(%) ...
3
votes
1answer
379 views

Color script output only when invoked from interactive shell

I made a bash script producing colored output. The colors are fine when the script is called from an interactive shell. However, if the output is processed in another script, or passed through a pipe, ...
2
votes
1answer
309 views

How to capture text formatting in bash?

The following shell script works but removes colored formatting generated by rspec: #!/bin/bash OUTPUT=`rspec` echo "$OUTPUT" How to preserve the colors?
4
votes
4answers
2k views

How do you colorize only some keywords for a bash script?

I am running some unit test code. The unit test code outputs regular text. There is a lot of the text so I want to highlight for the user important keywords. In this case the keywords are "PASS" and ...
6
votes
5answers
3k views

How to create a testcolor.sh like the following screenshot?

I found this image on the internet, but don't know how was it made, Can anyone provide a sample on that? I just would like to have a color table as well.