Search

Coloring the output of cat

The "cat" command is used to view the contents of a file with out opening it.
The cat displays the contents of the file in the same color as that of the terminal. This can be changed and cat can be made to display the text in a different color. This can be done using the command "tput".
We can chnage the terminal font using tput as shown below.



For e.g.



Now we will combine this with cat .
Let us say we have a file temp

temp:





Output:



We can put this in a script and allow the user to pass the number for the color as well as the file to be displayed on the command line.

cat_color:



Save it and give it execute permissions.



Execute it just like the cat command



Output:



To make this script to work like a command we can add the path to the script in the PATH as given in the post Making a script available in all folders or copy the script into /bin directory.

12 comments:

  1. Going to graduate school was a positive decision for me. I enjoyed the coursework, the presentations, the fellow students, and the professors. And since my company reimbursed 100% of the tuition, the only cost that I had to pay on my own was for books and supplies. Otherwise, I received a free master’s degree. All that I had to invest was my time. best cat food for older cats with bad teeth

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. With programmed feline feeders, you can plan your feline's dinners with same time or various.Best Automatic Cat Feeder Wet Food

    ReplyDelete
  4. Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. larger cats

    ReplyDelete
  5. Nice to read your article! I am looking forward to sharing your adventures and experiences. dog houses for big dogs

    ReplyDelete
  6. Aiman Online Quran Learning Academy is an impressive online academy for teaching the Quran.
    This leading online Quran academy from
    Pakistan provides you an excellent chance to have one
    to one online Quran classes with tajweed and learn the basic teachings of Islam.

    ReplyDelete
  7. Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info. beagle thyroid problems

    ReplyDelete
  8. We have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends. no pull dog harness reviews

    ReplyDelete
  9. Very interesting blog. Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definately interested in this one. Just thought that I would post and let you know. cat car carrier

    ReplyDelete
  10. Excellent and very exciting site. Love to watch. Keep Rocking. science diet sensitive stomach cat

    ReplyDelete