Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
List files in different colors ?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
dj_farid
l33t
l33t


Joined: 14 Jun 2004
Posts: 613

PostPosted: Mon Aug 16, 2004 1:57 pm    Post subject: List files in different colors ? Reply with quote

I have been making a nice .bash_profile. There are a few lines that looks like this: "cat filename". Is there a way to make the text from the files in different colors?

For example:
cat file1 <-is green
cat file2 <-is red

Thanks.
Back to top
View user's profile Send private message
bokkepoot
Tux's lil' helper
Tux's lil' helper


Joined: 14 Mar 2003
Posts: 123
Location: The Hague, The Netherlands

PostPosted: Mon Aug 16, 2004 2:29 pm    Post subject: Reply with quote

Just to clarify: You want the output of cat to be coloured depending on the filetype ?
Back to top
View user's profile Send private message
dj_farid
l33t
l33t


Joined: 14 Jun 2004
Posts: 613

PostPosted: Mon Aug 16, 2004 2:59 pm    Post subject: Reply with quote

No, It's like a one time action. I want to know if there is a command that lists a file in a specific color.

Quote:
$ cat .bash_profile
# /etc/skel/.bash_profile:
# $Header: /home/cvsroot/gentoo-src/rc-scripts/etc/skel/.bash_profile,v 1.10 200
2/11/18 19:39:22 azarah Exp $

#This file is sourced by bash when you log in interactively.
[ -f ~/.bashrc ] && . ~/.bashrc
echo
echo "-------------------------------------------------------------------------"
df -h | grep -v 'none'
echo "-------------------------------------------------------------------------"

cat /tmp/updates.txt | grep "ebuild"

echo
date


I want the output of /tmp/updates.txt to be in something else than white.
I hope this explanation explains what I am after :?
Back to top
View user's profile Send private message
tomchuk
Guru
Guru


Joined: 23 Mar 2003
Posts: 317
Location: Brooklyn, NY

PostPosted: Mon Aug 16, 2004 5:11 pm    Post subject: Reply with quote

try:
Code:

echo -e "\033[00;32m`cat /tmp/updates.txt`\033[00m"


Edit: BTW color definitions from dircolors -p:
Code:

# Below are the color init strings for the basic file types. A color init
# string consists of one or more of the following numeric codes:
# Attribute codes:
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white


So to change the normal green (00;32m) to bold red (01;31m) you'd use:

Code:

echo -e "\033[01;31m`cat /tmp/updates.txt`\033[00m"
Back to top
View user's profile Send private message
dj_farid
l33t
l33t


Joined: 14 Jun 2004
Posts: 613

PostPosted: Mon Aug 16, 2004 5:29 pm    Post subject: Reply with quote

Thanks! That seems to do the trick if I don't have the output piped to grep. Is there a way of getting around this?
If not, I could probably do another textfile that is already grepped...
Back to top
View user's profile Send private message
tomchuk
Guru
Guru


Joined: 23 Mar 2003
Posts: 317
Location: Brooklyn, NY

PostPosted: Mon Aug 16, 2004 5:36 pm    Post subject: Reply with quote

Why not just:
Code:

echo -e "\033[00;32m`grep ebuild  /tmp/updates.txt`\033[00m"


I never got why people cat a file and then pipe it to grep instead of just using grep.
Back to top
View user's profile Send private message
bokkepoot
Tux's lil' helper
Tux's lil' helper


Joined: 14 Mar 2003
Posts: 123
Location: The Hague, The Netherlands

PostPosted: Mon Aug 16, 2004 6:39 pm    Post subject: Reply with quote

The LDP has a chapter devoted to bash colourizing.

And people pipe the output of cat because they think pipes always come from the left hand side =)
Back to top
View user's profile Send private message
dj_farid
l33t
l33t


Joined: 14 Jun 2004
Posts: 613

PostPosted: Mon Aug 16, 2004 6:55 pm    Post subject: Reply with quote

Thanks! I think that I got the hang of this now. :D
That link is very useful.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum