Is it possible to change the output color without using echo? Something like "set color to yellow".
I have a script
#!/bin/bash
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e ${YELLOW}
cat file.txt | awk 'NR==1 { print $0; }'
echo -e ${BLUE}
cat file.txt | awk 'NR==2 { print $0; }'
echo -e ${NC}
which prints the first line of file.txt in yellow and the second line in blue. But it also adds extra lines in the places where I have "echo" commands.
I tried something like this:
#!/bin/bash
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
${YELLOW} cat file.txt | awk 'NR==1 { print $0; }'
${BLUE} cat file.txt | awk 'NR==2 { print $0; }' ${NC}
But it doesn't work because "echo" command needs -e parameter to display colors.
So my question is: Can I change the output color without using echo? If not, how to remove these extra lines between lines of the file? Is it possible to correct this script to not generate extra lines?
Current output:
first line of file.txt second line of file.txt
Desirable output:
first line of file.txt second line of file.txt
prinftinstead ofecho -e