Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to add '--color' with pipes? Post 302903614 by Don Cragun on Wednesday 28th of May 2014 03:24:23 PM
Old 05-28-2014
When you are shown that fgrep on some systems has a --color option (as in the fgrep man page excerpt vgersh99 provided), the way to get color output from fgrep would be:
Code:
fgrep --color -i "XYZ-1124354-P" mylog.log

but, you haven't told us what system you're using, so we don't know if fgrep on your system supports the --color option.

Furthermore, many utilities that have color options use the file descriptor associated with the utility's standard output to determine terminal characteristics to determine what escape sequences are needed to produce color on the terminal you're using. If your system's grep family of utilities supports a --color option and uses stdout to determine terminal type, piping the output from fgrep into another utility will disable color output. If your fgrep can't produce color output when stdout is connected to a pipe, you could still translate ASCII soh control characters to spaces using:
Code:
tr '\001' ' ' < mylog.log | fgrep --color -i 'XYZ-1124354-P'

but using sed G to produce double spaced output will be more complex:
Code:
fgrep -i 'XYZ-1124354-P' mylog.log | tr '\001' ' ' | sed G | grep --color -i -e 'XYZ-1124354-P' -e '^$'

This User Gave Thanks to Don Cragun For This Post:
 

4 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

PIPEs and Named PIPEs (FIFO) Buffer size

Hello! How I can increase or decrease predefined pipe buffer size? System FreeBSD 4.9 and RedHat Linux 9.0 Thanks! (1 Reply)
Discussion started by: Jus
1 Replies

2. Shell Programming and Scripting

Add color in CSV cells

hi, i have text file that file contains below information. Name,Roll,Mark,Total Sivasankar,2120,89,410 Raja,2212,87,425 i need to convert text file to CSV file also the heading(Name,Roll,Mark,Total) font should be BOLD and color should be RED. how can i set fonts in csv (5 Replies)
Discussion started by: rsivasan
5 Replies

3. Shell Programming and Scripting

Add Color To html Doc

I have a script which converts a .csv file to html nicely. Trying to add 3 colors, green, yellow and red to the output depending upon the values in the cells. Tried some printf command but just can't seem to get any where. Any ideas would be appreciated. nawk 'BEGIN{ FS="," print ... (7 Replies)
Discussion started by: jimmyf
7 Replies

4. UNIX for Beginners Questions & Answers

How to add 'color' in a grep?

Hello friends - I use various grep commands to search for data in a file. However, to add 'color' seems to not work. Is there a way to add color to two items that i search? so that i can easily identify in hundreds of lines of output what i am looking for? zegrep abcdefg... (7 Replies)
Discussion started by: DallasT
7 Replies
All times are GMT -4. The time now is 10:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy