grep Linux Command Cheatsheet




grep is a Linux command line utility to search plain text datasets using regular expressions.

Syntax

grep [options] search-pattern [file(s)]

Examples

Lets take following file as an example to perform grep operations

$ cat readme.txt
Hello World line1
Hello World line2
Hello World line3
Hello World line4
Hello World line5
$ grep 5 readme.txt
Hello World line5
$ grep line4 readme.txt
Hello World line4
$ grep Hello readme.txt
Hello World line1
Hello World line2
Hello World line3
Hello World line4
Hello World line5
$ grep -i hello readme.txt
Hello World line1
Hello World line2
Hello World line3
Hello World line4
Hello World line5
Note: -i is to ignore case


┬ęCopyright 2020 OneCompiler | Privacy Policy | Terms & Conditions