Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using grep in less output

 
Joe Harry
Ranch Hand
Posts: 10122
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

I want to grep for a text in the output of a less command. Is there a way to combine these two using the pipe operator and achieve my goal?
 
Joe Harry
Ranch Hand
Posts: 10122
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This does what I want, but how to color differentiate my search text?

grep -i 'text' < bigfile.txt | less
 
Joe Harry
Ranch Hand
Posts: 10122
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some googling produced me this which is what I wanted.

grep --color=always -i "text" bigfile.txt | less -R

What does the -R stand for? Is this the Red color?
 
Joe Harry
Ranch Hand
Posts: 10122
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without using the -R option, I get garbage for the matched text in the less output.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-r or -R stand for "raw", and they tell less to pass control characters through unchanged. The default is to display them textually -- not as "garbage", really, but for example to show the three ASCII letters "ESC" instead of the control character named "escape". "-r" means to do this for all characters, while "-R" means to do this only for those characters that control coloring and highlighting in a terminal, the so called "ANSI escape sequences."
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic