0% found this document useful (0 votes)
7 views4 pages

1.document Grep Command Part 1

This document provides an overview of the grep command in bash shell scripting, which is used to search for strings in files. It outlines the basic syntax and various options available for the grep command, including both basic and advanced options. The document emphasizes how these options can be utilized to automate common tasks in scripting.

Uploaded by

bwayne1247
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

1.document Grep Command Part 1

This document provides an overview of the grep command in bash shell scripting, which is used to search for strings in files. It outlines the basic syntax and various options available for the grep command, including both basic and advanced options. The document emphasizes how these options can be utilized to automate common tasks in scripting.

Uploaded by

bwayne1247
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Bash Shell Scripting

grep command
Part-1

Learn how to automate common tasks using bash shell scripting


grep command:
 Grep is a filter command, it is used to search a string in a given file.

 Simple grep command syntax:


 grep [options] “string/pattern” file/files
 cat file | grep [options] “string/pattern”
 echo “some text” | grep [options] “string/pattern”

 Basic options: -i -w -v -o -n -c -A -B -C -r -l -h
 Advanced Options: -e -f and –E

Learn how to automate common tasks using bash shell scripting


Grep command with basic options
 Basic options: -i -w -v -o -n -c -A -B -C -r -l -h
 grep “string/pattern” file/files
 grep [options] “string/pattern” file/files
 -i To ignore case for matching/searching
 -w To match a whole word
 -v To display the lines which are not having given string or text
 -o To print/display only matched parts from matched lines
 -n To display the matched line numbers
 -c To display matched number of lines
 -A To display N lines after match (grep –A 3 “string” file)
 -B To display N lines before match
 -C To display N lines around match
 -r To search under current directory and its sub-directory
 -l To display only file names
 -h To hide file names
Learn how to automate common tasks using bash shell scripting

You might also like