color print using perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting color print using perl
# 1  
Old 03-01-2012
color print using perl

Hi
i want to print the text in different color using perl script.
i am able to print on console(terminal).
but if i try to print the same into a file, i am not able to do
color.pl
Code:
#!/bin/usr/perl
use Term::ANSIColor;
print "This text is normal.\n";
use Term::ANSIColor qw(:constants);
$Term::ANSIColor::AUTORESET = 1;
print BOLD BLUE "This text is in bold blue.\n";
print "This text is normal.\n";

if try the following

Code:
#!/bin/usr/perl
use Term::ANSIColor;
open (OUT,">cl.txt"); 
print OUT "This text is normal.\n";
use Term::ANSIColor qw(:constants);
$Term::ANSIColor::AUTORESET = 1;
print OUT BOLD BLUE "This text is in bold blue.\n";
print OUT "This text is normal.\n"; 
close(OUT);

vi cl.txt
Code:
This text is normal.
^[[1m^[[34mThis text is in bold blue.
^[[0m^[[0mThis text is normal.

i am not getting output in color inside the file cl.txt

thanks
roopa

Moderator's Comments:
Mod Comment How to use code tags

Last edited by Franklin52; 03-01-2012 at 03:11 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 03-01-2012
Obviously, in a text editor you'll see the raw formatting code that make text bold and beautiful.
Try cat c1.txt and you'll see what you want.
# 3  
Old 03-01-2012
Is there any way to get color print inside text editor?
# 4  
Old 03-01-2012
That's not the way a text editor (vi or emacs) works or may be I'm not aware.

1. Ok, tell me this: if you want you want to manually change the formatting codes (say, change colour from blue to green) by yourself instead of a perl program doing it, how will you achieve this task?
2. Why do you need to see coloured text in an editor? Rather, you could familiarise yourself with the formatting codes.
3. What is the exact requirement?
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. AIX

How to print color text in AIX?

Hi I'd like to print color text and I've tried this: echo "\033but it didn't woked. When I changed 0 --> 1/4/5, the text "HI" --> bold/underline/blink, but when I changed 31 or 33 to other values, the color didn't change. What's the problem. Need to install something ??? (8 Replies)
Discussion started by: bobochacha29
8 Replies

2. Shell Programming and Scripting

creating color palette using awk or perl

Hi, I'm wondering if anyone have tried creating a color palette or table using awk or perl using a range of values. thanks for any suggestion in advance. 0-0.1: purple 0.1-0.2: blue 0.2-0.3: green 0.3-0.4: yellow 0.4-0.5: orange > 0.5: red Happy holidays,:) (5 Replies)
Discussion started by: ida1215
5 Replies

3. Shell Programming and Scripting

how to get the Format header in perl in different color

Now here is the problem how to get the Format header in perl in different color. format RPT_TOP= DINISO EXECUTION REPORT @<<<<<<<<<<<<< AGAINST SEOPACTUAL Page : @>>> $TODAY,$%... (3 Replies)
Discussion started by: rrd1986
3 Replies

4. UNIX for Dummies Questions & Answers

Print in color

I have a short code below: awk 'NR==1 {printf "'$information'-MYDATA-'$information' \n"} {print $0}' data.file > newdata.file I want the "information" color in RED and MYDATA in BLUE. How can I do it? Please help!!!! (3 Replies)
Discussion started by: bobo
3 Replies
Login or Register to Ask a Question