To use grep, you enter grep search_expression file_name
grep vnc /var/log/messages.
When working with grep at the command line, you can use the following options:
• –i Ignores case when searching for the text.
• –l Displays only the names of the files that contain the matching text. It doesn’t display the actual matching line of text.
• –n Displays matching line numbers.
• –r Searches recursively through subdirectories of the path specified.
• –v Displays all lines that do not contain the search string.
In addition to egrep, you can also use the fgrep (fixed-string grep) utility to search for content within files. The fgrep utility searches files for lines that match a fixed string. Unlike egrep, it does not perform searches for regular expressions. Instead, fgrep uses direct string comparisons to find matching lines of text in the input. The syntax is fgrep pattern filename. For example, running the fgrep server *.c command searches for the string “server” in all files in the current directory whose filename has a “.c” extension.
Running fgrep is the same as running grep –F. When using regular expressions, including text with the * or ? wildcard characters (such as "*.c") is called a file globbing pattern.
No comments:
Post a Comment