Multi-Colored Text File
Hi. I'd like to create regular ASCII text files in Linux, but I'd also like some words to be in different colrs: red, blue, green, etc, and then print them.
Is this possible with regular text files? If not, what is the easiest way to do this? |
A regular text file is just that, a plain old simple text files with only alphanumeric characters.
If you would like to have certain words/lines formatted with different color attributes, you need to insert some control codes into the file. I did this some time ago when I wanted to show my Pre-Login banner using different colors. Here is the modified shell script with an example text file. Code:
#! /bin/sh Code:
[blue]This is blue text. [bold_on]This is blue text that's bold.[bold_off] Hope this helps. |
That's nice, but it doesn't help my scenario. I need to print the file, not merely display the file on the computer screen. When I print the output from your program on a real printer, it's all in black ink.
|
You seem to be missing the point. Again, a text file on its own doesn't have that ability. It's just a series of bytes that represent text characters in some character encoding. The only colors or formatting you could get would come from some other program interpreting the data contained and displaying it in an appropriate manner.
As an example, a web page is just a text file. Open up an html source file in a regular text browser and you'll see the raw text. But that text includes html mark-up codes, and if you open it in a browser window that mark up will be interpreted and formatted into a web page. That is, only a program with an html parser built in will be able to display it the way it's intended. Colors in the console shell work the same way, except that the mark-up is in the form of ansi escape codes. Only a program that understands the escapes will be able to show you actual colors. Any other text viewer will just display the raw codes. So your only option is to write up and store the text in a way that allows you to use colors. I recommend using something like libreoffice. Then you can either print it directly or save it as an .odf, .doc, or .pdf, any of which can hold color formatting and allow them to be displayed in their appropriate viewers. But it won't be a plain text file after that. |
@OP: Several people have asked similar questions on the SuperUser and StackExchange forums.
Do a Google search for "Printing Multi-Colored Text file to lp0". |
Perhaps something like the following would work?
http://www.physics.emory.edu/~weeks/...s/colorps.html |
Quote:
Code:
printf "\033[2;32mHello\033[0m" |
All times are GMT -5. The time now is 12:30 PM. |