Results 1 to 4 of 4

Thread: using grep to only highlight (not focus on) certain words

  1. #1
    Join Date
    Jul 2011
    Location
    Florida, USA
    Beans
    21
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    using grep to only highlight (not focus on) certain words

    whenever searching a "man" page for a particular program ( e.g man <program> | grep <word to highlight> ), how do I get it to just highlight the word specified using "grep" and also show the whole man page along with that? cause on the output it seems to just focus on some of the descriptions around the word I highlighted, and not show the whole man page with the grepped word highlighted in there.

  2. #2
    Join Date
    Jul 2012
    Location
    Scotland
    Beans
    255
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: using grep to only highlight (not focus on) certain words

    I'm confused - you could simply:

    Code:
    man vi
    To get the man page for vi... or you could also use:

    Code:
    apropos vi
    Which is an alternative. Can you explain in detail what you mean exactly? If you're grepping for a search phrase, like a function or something, then I have no idea how to highlight

  3. #3
    Join Date
    Dec 2007
    Beans
    12,521

    Re: using grep to only highlight (not focus on) certain words

    Quote Originally Posted by Ohzed View Post
    whenever searching a "man" page for a particular program ( e.g man <program> | grep <word to highlight> ), how do I get it to just highlight the word specified using "grep" and also show the whole man page along with that? cause on the output it seems to just focus on some of the descriptions around the word I highlighted, and not show the whole man page with the grepped word highlighted in there.
    I don't think what you want is possible.

  4. #4
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: using grep to only highlight (not focus on) certain words

    grep supports -A -B options allowing to print a defined number of lines before/after match, which allows to see bigger chunk of text. eg grep -A 20 -B 20 will show match with 20 preceding and 20 following lines.

    also you can try to hack it with sed and using color codes around the desired phrase
    eg
    Code:
    $ echo $'abc def ghi\n111 def x\nxxx def a def' | sed 's/def/^[[31m&^[[m/g'
    abc def ghi
    111 def x
    xxx def a def
    ^[ is produced by CTRL+V,ESC

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •