Skip to content

Basic usage of grep command

Introduction

Grep stands for “global regular expression print”. It is a command-line utility that is used for text search and pattern matching. It is one of the most powerful and commonly used tools in Unix-based operating systems. Grep command is generally used to search for specific strings or patterns in a file or files. In this blog post, we will discuss the most common usage of the grep command.

Usage

grep -i      # ignore case sensitivity
grep --color # highlight matches
grep -v      # search for non-matching lines
grep -o      # display only the matched part of the line
grep -A 1    # display the line matched and the next line
grep -B 1    # display the line matched and the previous line
grep -C 1    # display the line matched, the previous line, and the next line
Feedback