I have a shell script which is redirecting a specific line from a file using sed.
sed -n "${line_num}p" $1 >> output.txt
I want to color this line before redirecting the line to output.txt.
How I can do it?
I have a shell script which is redirecting a specific line from a file using sed.
sed -n "${line_num}p" $1 >> output.txt
I want to color this line before redirecting the line to output.txt.
How I can do it?
As noted, "text" has no color. But you can do something like this:
BLUE=$(tput setaf 4)
NONE=$(tput op)
sed -n "${line_num}p" $1 | sed -e 's/^\(.*\)$/'"$BLUE"'\1'"$NONE"'/' >> output.txt
to add terminal-specific escape sequences to the output.
tput is a (n)curses utility which (see manpage) looks up terminal capabilities and prints the result -- which you can save into a variable and use in a script. See for example these: