aspose file tools*
The moose likes Linux / UNIX and the fly likes Using grep in less output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Using grep in less output" Watch "Using grep in less output" New topic
Author

Using grep in less output

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

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?


SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

This does what I want, but how to color differentiate my search text?

grep -i 'text' < bigfile.txt | less
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

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

Joined: Sep 26, 2006
Posts: 9243
    
    1

Without using the -R option, I get garbage for the matched text in the less output.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

-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."


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using grep in less output
 
Similar Threads
finding out versions
Search tool to search all class files
File find utility?
how to use grep in regular expression java
struts2: Generating list of localisation keys?