Text file colors


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Text file colors
# 1  
Old 09-13-2010
Text file colors

Hi everyone.
I want to create a text file using different colors, but i dont know how to do that.
I just can set the color for the -screen- output, using. for example:
printf "\033[32m"
printf "%-20s\n" "Orange colour"
printf "\033[mo"
but if i redirect the second line output to a text file, it doestn do it with colours...

does anybody now how to do that ?
# 2  
Old 09-13-2010
Hi.

Welcome to the forum.

This script shows that the codes are written to redirected files:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate terminal color codes on disk.

# Utility functions: print-as-echo, print-line-with-visual-space.
pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }

# Write codes and text to scratch file t1.
{
printf "\033[32m"
printf "%-20s\n" "Orange colour"
printf "\033[mo"
} > t1

pl " Results of dump of file t1, showing codes exist:"
od -bc t1

exit 0

producing:
Code:
% ./s1

-----
 Results of dump of file t1, showing codes exist:
0000000 033 133 063 062 155 117 162 141 156 147 145 040 143 157 154 157
        033   [   3   2   m   O   r   a   n   g   e       c   o   l   o
0000020 165 162 040 040 040 040 040 040 040 012 033 133 155 157
          u   r                              \n 033   [   m   o
0000036

When I cat this file, the colored text appears on my screen, the emulator Terminal 2.22.3 from Gnome desktop (although in green, not orange).

Best wishes ... cheers, drl

The environment for this execution was:
Code:
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0 
GNU bash 3.2.39
printf - is a shell builtin [bash]

Note how code and data are far more legible when used within CODE tags. Select the text, then click the # just above the editing window.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. Shell Programming and Scripting

Help needed in sending file content with colors and borders

HI i am running a shell script in cron and storing the output of that script in a file say test.then i am copying the content of test to test1 and i will send the output of test to some email ids using mutt. Next time when the script executes i am comparing the contents of test and test1 and... (3 Replies)
Discussion started by: venkitesh
3 Replies

3. Shell Programming and Scripting

Removing Colors and ^M in a log file

Hi, I'm trying to send a log file to mailx as a "Body Message" but since the file contains so many control and color characters it's making an attachement out of it instead of putting it in the body. The file looks like this: Bringing up loopback interface: ^^M^MŽ 19 Bringing up interface... (18 Replies)
Discussion started by: dgtek
18 Replies

4. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

5. UNIX for Dummies Questions & Answers

Converting a text file with irregular spacing into a space delimited text file?

I have a text file with irregular spacing between values which makes it really difficult to manipulate. Is there an easy way to convert it into a space delimited text file so that all the spaces, double spaces, triple spaces, tabs between numbers are converted into spaces. The file looks like this:... (5 Replies)
Discussion started by: evelibertine
5 Replies

6. Shell Programming and Scripting

Create multiple text file from a single text file on AIX

Hi I need to create multiple text files from onc text file on AIX. The data of text files is as below: ********************************************** ********************************************** DBVERIFY: Release 10.2.0.4.0 - Production on Tue Nov 10 13:45:42 2009 Copyright (c) 1982,... (11 Replies)
Discussion started by: lodhi1978
11 Replies

7. Shell Programming and Scripting

how can I bcp out a table into a text file including the header row in the text file

Hi All, I need to BCP out a table into a text file along with the table headers. Normal BCP out command only bulk copies the data, and not the headers. I am using the following command: bcp database1..table1 out file1.dat -c -t\| -b1000 -A8192 -Uuser -Ppassword -efile.dat.err Regards,... (0 Replies)
Discussion started by: shilpa_acc
0 Replies

8. UNIX for Dummies Questions & Answers

Colors

Is there a way with the bourne shell to have different types of files show up a different color when you do ls? (1 Reply)
Discussion started by: resullivan
1 Replies

9. UNIX Desktop Questions & Answers

colors

Hello, I am somewhat new to linux. I just installed Red Hat 7.2 and when I try to load gnome or KDE in colors above 8bit it will kind of lock up and display some wierd scrambled cable look. I have an ATI Radeon 7000. I check out my monitor settings they are fine. Is it the graphics card? I set my... (1 Reply)
Discussion started by: Sage3k
1 Replies

10. UNIX for Dummies Questions & Answers

Changing korn shell script text Menu colors?

Is it possible to change the color of text in a korn shell script Menu? I can change the color of session text through my telnet client but I want to be able to change color text in the Korn shell menu to highlight certain items. (6 Replies)
Discussion started by: darthur
6 Replies
Login or Register to Ask a Question