Searches a file for a literal string.
fgrep [ -h] [ -i] [ -s] [ -v] [ -w ] [ -x] [ -y ] [ [ -b] [ -n] | [ -c | -l | -q ] ] [ -pSeparator] {Pattern | -ePattern | -fStringFile} [File...]
The fgrep command searches the input files specified by the File Parameter (standard input by default) for lines matching a pattern. The fgrep command searches specifically for Pattern parameters that are fixed strings. The fgrep command displays the file containing the matched line if you specify more than one file in the File parameter.
The fgrep command differs from the grep and egrep commands because it searches for a string instead of searching for a pattern that matches an expression. The fgrep command uses a fast and compact algorithm. The $, *, [, |, (, ) and \ characters are interpreted literally by the fgrep command. These charactors do not recognize full regular expressions like the egrep command. Since these characters have special meaning to the shell, the entire string should be enclosed in single quotes ('...'). If no files are specified, the fgrep command assumes standard input. Normally, each line found is copied to the standard output. The filename is printed before each line found if there is more than one input file.
Notes:
- The fgrep command is the same as the grep command with the -F flag, except that error and usage messages are different and the -s flag functions differently.
- Lines are limited to 2048 bytes.
- Paragraphs (under the -p flag) are currently limited to a length of 5000 characters.
- Do not run the grep command on a special file because it produces unpredictable results.
- Input lines should not contain the NULL character.
- Input files should end with the new line character.
- Although some flags can be specified simultaneously, some flags override others. For example, if you specify -l and -n together, only file names are written to standard output.
This command returns the following exit values:
0 | A match was found. |
1 | No match was found. |
>1 | A syntax error was found or a file was inaccessible (even if matches were found). |
fgrep strcpy *.c
This searches for the string strcpy in all files in the current directory with names ending in the .c character string.
This displays the number of lines in pgm.c that contain left and right braces.
If you do not put more than one { (left brace) or one } (right brace) on a line in your C programs, and if the braces are properly balanced, the two numbers displayed are usually the same if the proper conditions are met. If the numbers are not the same, you can display the lines that contain braces in the order that they occur in the file with:
egrep {|} pgm.c
This searches the files in the current directory that end with .cand displays the names of those files that contain the strcpy string.
/usr/bin/fgrep | Contains the fgrep command. |
/bin/fgrep | Symbolic link to the fgrep command. |
The ed command, egrep command, grep command, sed command.
Files Overview in AIX 5L Version 5.2 System User's Guide: Operating System and Devices introduces you to files and the way you can work with them.
Input and Output Redirection Overview in AIX 5L Version 5.2 System User's Guide: Operating System and Devices describes how the operating system processes input and output.