--- layout: page author: Domenico Votta category-page: advanced category-title: Advanced commands tags: search for occurencies title: grep previous-page: pages/cmd/advanced/emacs.html next-page: pages/cmd/advanced/head-tail.html --- grep is a command that allows you to search occurrences of one or more keywords in one or more files. Through some flags you can decide on the search criteria. The command grep is case sensitive (robot is different from Robot), but we will see how to ignore that.
Here we have two files named example1.txt and example2.txt that contain 5 elements, to test this command: example1.txt {% highlight bash %} Car Computer Robot Smartphone Videogame {% endhighlight %} example2.txt {% highlight bash %} Apple Computer Robot Microsoft Huawei {% endhighlight %} The syntax command is:
grep [flag] [keyword] [file]
You can put different flags together to refine the search.
grep Robot example1.txt example2.txt (if you write robot you won't have the correspondence.)
    example1.txt: Robot
    example2.txt: Robot
Your output will be this because grep found the keyword Robot in both files

Flags

Here a list that contains the main flags of these command: