grep in Bash

h‮ptt‬s://www.lautturi.com
grep in Bash

The grep command is a utility in Unix and Linux that searches for a specified pattern in a given input. It can be used to search for patterns in files, directories, or the output of other commands.

Here is the basic syntax for using grep in the Bash shell:

grep pattern input

Here is an example of using grep to search for the pattern "test" in the file file.txt:

grep "test" file.txt

This will print all the lines in the file file.txt that contain the pattern "test."

You can also use grep to search for patterns in multiple files by specifying multiple file names as the input. For example:

grep "test" file1.txt file2.txt file3.txt

This will search for the pattern "test" in the files file1.txt, file2.txt, and file3.txt and print the matching lines from all the files.

grep has many options that allow you to customize the search. For example, you can use the -i option to perform a case-insensitive search, or the -v option to print only the lines that do not match the pattern. You can see a full list of options by typing man grep in the terminal.

Created Time:2017-10-28 20:40:40  Author:lautturi