Skip to content

Instantly share code, notes, and snippets.

@caillioux
Last active May 25, 2019 08:45
Show Gist options
  • Select an option

  • Save caillioux/72f9cc03a45174880e1ddc90813def45 to your computer and use it in GitHub Desktop.

Select an option

Save caillioux/72f9cc03a45174880e1ddc90813def45 to your computer and use it in GitHub Desktop.

A grep command to search for a popular string in a vendor/ directory.

It aims to be more efficient (performance, readability) than what IDE commonly do :

grep -rlP 'sylius\.grid' vendor/ | grep -vP 'xml|Test|rst'

  1. Find all occurences in vendors -r vendor/ with a regex -P for 'syliusDOTgrid', 'DOT' being a real dot between 'sylius' and 'grid', but only display file names -l to avoid dozens of matches being in those files
  2. Pipe | results and exclude grep -v with a regex -P files containing 'xml', 'Test' or 'rst' xml|Test|rst in their path, since these files usually have lots of occurences and not the golden piece of code you search for ;)

It remains simple to write and efficient, do you have other tips with grep?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment