Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

grep

20 views
Skip to first unread message

nicky

unread,
May 31, 2012, 5:26:14 PM5/31/12
to

I would like to create a grep to be able to colorize and
indent phrases in this way. Is it possible to do that in grep ? Please
help me.
Thanks

1. word word word word word word word word word word word word word
word word word word word word etc, (black)
1.1. word word word word word word word word word word word word
word word word-red
1.1.1 word word word word word word word word word word
word word word word word word word word word word word word word
word word word word (blue)
1.1.1.1 (green)

2. word word word word word word word word word word word word word
word word word word word word etc, (black)
2.1. word word word word word word word word word word word word
word word word word word word word word word word word word word
word word word word word (red)
2.1.1 word word word word word word word word word word word word
word word word word word word word word word word word word word
word word word (blue)
The number of phrases are infinite

Tim Roberts

unread,
Jun 1, 2012, 2:57:47 AM6/1/12
to
nicky <nicolas_l...@hotmail.com> wrote:
>
> I would like to create a grep to be able to colorize and
>indent phrases in this way. Is it possible to do that in grep ?

Grep doesn't do that. Grep searches through files and prints the lines
that contain the search phrase.

However, I suspect you didn't really mean "grep" here. Perhaps you should
try stating your problem again. What goes in, and what comes out? Are you
displaing to a terminal or printing to PostScript?
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Eric Pement

unread,
Jun 1, 2012, 2:05:23 PM6/1/12
to
On Friday, June 1, 2012 1:57:47 AM UTC-5, Tim Roberts wrote:
> nicky <nicolas_l...@hotmail.com> wrote:
> >
> > I would like to create a grep to be able to colorize and
> >indent phrases in this way. Is it possible to do that in grep ?
>
> Grep doesn't do that. Grep searches through files and prints the lines
> that contain the search phrase.
>
> However, I suspect you didn't really mean "grep" here.

No, I think he really did mean grep, but he was referring to GNU grep. Try this command to see it with GNU grep:

echo hello | grep --color=always "he"

From a GNU/Linux shell prompt, type "info grep" and consult the info page for the environment variable called "GREP_COLORS". Eight color possibilities are set by default, with at least 10 options that can be set.

However, the info pages on the color options are difficult to read, and I suspect that Nick was hoping for alternating color possibilities, based on different regular expressions.

If I am reading the info pages correctly, what he's asking is not possible, even given the large array of options in GREP_COLORS. Setting different color combination to (mt,ms,mc) variable components will not cause different colors to be applied to alternate egrep patterns "like|this|or|that".

But if I'm misreading the info pages, someone please correct me.

Eric Pement

Eli the Bearded

unread,
Jun 1, 2012, 4:59:59 PM6/1/12
to
In comp.editors, Eric Pement <eric....@gmail.com> wrote:
> On Friday, June 1, 2012 1:57:47 AM UTC-5, Tim Roberts wrote:
>> nicky <nicolas_l...@hotmail.com> wrote:
>>> I would like to create a grep to be able to colorize and
>>> indent phrases in this way. Is it possible to do that in grep ?
>> Grep doesn't do that. Grep searches through files and prints the lines
>> that contain the search phrase.
>> However, I suspect you didn't really mean "grep" here.
> No, I think he really did mean grep, but he was referring to GNU grep.

That's ggrep, then. Seriously, there are a lot of versions of grep,
and they each have different functionality. /usr/bin/grep on Solaris
is nothing like /usr/bin/grep on Ubuntu.

Well, for some values of "nothing" at least.

> Try this command to see it with GNU grep:
>
> echo hello | grep --color=always "he"

echo hello | ggrep --color=always "he"
^[[01;31m^[[Khe^[[m^[[Kllo

Charming, ain't it. And near as I can tell, gnu grep will identify
all intra-line matches for coloring, but doesn't have an option to
print the total number of matches, just the posix "-c" which prints
number of lines with matches. A victory of gloss over substance.

ObEditors:
:set hlsearch
turns on a similar coloring thing in vim

Elijah
------
does not use colors in ggrep or vim
0 new messages