About Us Products Services Contact Us
Manucomp | Home
1 Year Warranty Call us Toll-Free at : 1-866-440-1115
 

Fgrep

Fgrep

At this point you might be wondering how fgrep fits in with the others. fgrep is essentially grep (or egrep) with no special characters. If you want to search for a simple string without wild cards, use fgrep. The fgrep version of grep is optimized to search for strings as they appear on the command line, so it doesn't treat any characters as special. You could use fgrep in the above examples to more efficiently search for the plain string "hello," and also to search for strings that contain special characters used in their usual sense. For example, if you wanted to search for "hello" at the end of a sentence, you would want to search for "hello." (hello followed by a period). The dot or period is a special character in grep or egrep, but fgrep simply treats a period as a period and not as a special character.

$ fgrep 'hello.' *

I have two final notes about searching for multiple strings. Multiple search patterns can be placed on a single command line by using the -e option. The following example will search for "cat" or "dog":

$ fgrep -e 'cat' -e 'dog' *

You can also list search patterns in a file and name the file on the command line with the -f option. The example below is a file named searchfor.txt that contains a list of search patterns for the singular or plural of various animals. The question mark at the end of each animal name applies to the preceding "s" and means zero or one occurrence of that letter.

dogs? cats? ducks? snakes?

To use this file to search another list of files, name it on the command line instead of a search pattern. The egrep utility will search for all the possible strings listed in searchfor.txt:

$ egrep -nf searchfor.txt *


 
Copyright © Manucomp 2005. All Rights Reserved. Disclaimer | Privacy Policy
All Sun and Cisco products come with 1 year warranty
Canadian 6-7007 Islington Avenue • Toronto, Ontario, Canada • L4L 4T5 •
Phone : 416-484-0781 • Fax : 416-946-1267 • Toll-Free: 1-866-440-1115
USE OF TRADEMARKS
This site is independent of and does not represent any manufacturer or company for which products may be displayed on this web site. Additionally, said manufacturers do not officially sponsor, approve, or endorse this site or its content. All associated or other logo's found on this site are registered trademarks of their respective owners.