Select Page

ABIOLA RASP – Raspberries for African School Projects

Wie können wir helfen?

< Alle Themen
Print

Searching for pattern in file or dir

no-813 au-03

Searching a specific pattern in a file

grep is the one of the usefull command to search a specific pattern in a file. You can check your pattern whether or not in a file. In our example, we’ll search abiola keyword in results.txt.

1) Here is the file.

2) Run below command to search a pattern.

grep “abiola” results.txt

3) It found our keyword.

FORMAT:
grep keyword file

keyword = abiola
file = results.txt

Searching a specific pattern in a dir

You need to use grep command with -r parameter to search a patter in a directory.

1) This is our directory and it contains many files.

2) Run below command to search a pattern

grep -r “abiola” Abiola/

3) It found our pattern in results.txt

FORMAT:
grep -r keyword dir

keyword = abiola
dir = Abiola/

This article is a component of the “Linux Introduction” course from the ABIOLA online Academy.

Please refer: https://academy.abiola.ngo/courses/linux-introduction/?lang=en

Inhaltsverzeichnis