0% found this document useful (0 votes)
25 views

Unix Basic Commands - Grep

The grep command searches files for lines containing a pattern and returns a status code of 0 if matches are found, 1 if not, or 2 for errors. It has options like -b to show line numbers, -c for count of matched lines, and -i for case-insensitive matching. An example shows using -c to count matches in a file.

Uploaded by

Rocky
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Unix Basic Commands - Grep

The grep command searches files for lines containing a pattern and returns a status code of 0 if matches are found, 1 if not, or 2 for errors. It has options like -b to show line numbers, -c for count of matched lines, and -i for case-insensitive matching. An example shows using -c to count matches in a file.

Uploaded by

Rocky
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

UNIX BASIC COMMANDS: GREP

The grep command allows you to search one file or multiple files for lines that contain a
pattern. Exit status is 0 if matches were found, 1 if no matches were found, and 2 if errors
occurred.

SYNTAX
The syntax for the grep command is:
grep [options] pattern [files]

OPTIONS
Option

Description

-b

Display the block number at the beginning of each line.

-c

Display the number of matched lines.

-h

Display the matched lines, but do not display the filenames.

-i

Ignore case sensitivity.

-l

Display the filenames, but do not display the matched lines.

-n

Display the matched lines and their line numbers.

-s

Silent mode.

-v

Display all lines that do NOT match.

-w

Match whole word.

EXAMPLE
grep -c tech file1

* Please note that there are many flavors of UNIX, so if in doubt, consult your man pages

You might also like