bash: color strings in log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash: color strings in log file
# 1  
Old 06-02-2008
bash: color strings in log file

hello
im looking for an easy way to color specific strings in text file.
simple example:

cat file1
acb 1234
qwer 5678

my goal:
cat file1 (color the acb red and the 5678 blue)
acb 1234
qwer 5678


cheers
# 2  
Old 06-02-2008
This should at least get you started.

Code:
cat file1 | while read par1 par2
do
  printf "\033[31m%-10s\033[0m" $par1
  printf "\033[34m%10s\n\033[0m" $par2
done

Hope it helps.
# 3  
Old 06-03-2008
Also man tput (or rather, google for examples, because the manual isn't very helpful).
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

color in bash

I have some tcsh scripts that produce output in color, but does not work in bash. Any idea on a solution? echo " \033 (6 Replies)
Discussion started by: kristinu
6 Replies

2. Shell Programming and Scripting

Using arrays in bash using strings to bash built-in true

I have the following code and for some reason when I call the program using /home/tcdata/tatsh/trunk/hstmy/bin/bash/raytrac.bash --cmod=jcdint.cmod I get hasArgument = hasArgument = true Somehow the array element is returning even though I have not chosen the option. ... (41 Replies)
Discussion started by: kristinu
41 Replies

3. Shell Programming and Scripting

Bash - changing a color of a substring

Hello! I need to write a bash script for my university classes, and I came up with an idea of a program that would test the speed of typing - there is some random text that you have to rewrite, and the script measures time, number of mistakes etc. The text would be visible on the screen all... (3 Replies)
Discussion started by: xqwzts
3 Replies

4. Shell Programming and Scripting

Extracting strings from a log file.

I'm new to all this and I've been fiddling with this problem for HOURS and feel silly that I can't work it out! I have a .log file that VERY long and looks like this: 2011-08-31 10:03:34 SUESTART AG Amndmnt Client WebRequest DNU SUEEND Sequence: 600, 2011-08-31 10:03:34 SUESTART... (11 Replies)
Discussion started by: SusieSA
11 Replies

5. OS X (Apple)

Adding Color to bash

Hey everyone, I have come across an issue to where I am trying to create a script which changes the text color with a simple if then statement. I have seen it done with Fedora 8 but when I try and create it using my MacBook Pro running Snow Leopard it doesn't work. Funny thing is, when I use... (2 Replies)
Discussion started by: dachadster13
2 Replies

6. Shell Programming and Scripting

Changing font and color in log file of Script

Hi, We have process log with user defined error messages and information echos. I wanted to highlight error messgaes in that log file while writing in it. Is there any option with either echo or any other command which enables making text bold or we can change the font of body text of echo. ... (4 Replies)
Discussion started by: satgo
4 Replies

7. UNIX for Dummies Questions & Answers

How to get rid of all the weird characters and color on bash shell

Does anyone of you know how to turn off color and weird characters on bash shell when using the command "script"? Everytime users on my server used that command to record their script, they either couldn't print it because lp kept giving the "unknown format character" messages or the print paper... (1 Reply)
Discussion started by: Micz
1 Replies
Login or Register to Ask a Question