LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-11-2011, 01:17 AM   #1
Jerry Mcguire
Member
 
Registered: Jul 2009
Location: Hong Kong SAR
Distribution: RedHat, Fedora
Posts: 143

Rep: Reputation: 17
bash coloring output


Hi,

I want to `cat` any text file to screen with alternate text color for the alternate lines. Is there any simple command to do that in bash?

e.g.
Code:
$ cat /etc/hosts | coloring.sh
Also, how does a bash script accepting pipe input know when to stop? Thanks.

J.
 
Old 08-11-2011, 01:44 AM   #2
Jerry Mcguire
Member
 
Registered: Jul 2009
Location: Hong Kong SAR
Distribution: RedHat, Fedora
Posts: 143

Original Poster
Rep: Reputation: 17
Thanks. I got it.

http://www.linuxquestions.org/questi...mostly-229142/

Code:
#!sh
i=0
while read line
do
  if [ "$i" -eq "0" ]
  then
                echo -e "\e[1;34m${line}\e[0m"
                i=1
  else
                echo -e "\e[1;31m${line}\e[0m"
                i=0
  fi
done
exit 0
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash; awk or sed output to variable: how keep newline at end of each output line porphyry5 Programming 3 06-10-2011 05:50 PM
file coloring Ribo01 Linux - Newbie 2 11-27-2010 04:44 PM
coloring TAB output for filename completion glinux Linux - Newbie 0 03-02-2009 10:34 PM
bash ls not coloring files, directories etc mr_smith Red Hat 2 08-30-2006 07:05 AM
[LaTeX] Coloring environments solarize Linux - Software 3 09-04-2005 03:54 PM


All times are GMT -5. The time now is 06:54 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration