I have a list of filtered files found by grep
by a specific regex, but want to use the results of that filtered list of files to further grep
those results only.
Filtering a Magento 2 code base for file names only: grep -Ril
(-i only because I tried to use extra filtering on regex)
grep -Ril 'catalog_product_index_eav' vendor/
vendor/magento/module-catalog/Model/ResourceModel/Layer/Filter/Decimal.php
vendor/magento/module-catalog/Model/ResourceModel/Layer/Filter/Attribute.php
vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/Decimal.php
vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php
vendor/magento/module-catalog/etc/db_schema.xml
vendor/magento/module-catalog/etc/db_schema_whitelist.json
vendor/magento/magento2-base/dev/tests/static/testsuite/Magento/Test/Integrity/_files/dependency_test/tables_ce.php
vendor/magento/magento2-base/dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/SourceTest.php
vendor/magento/magento2-base/dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Search/FilterMapper/StockStatusFilterWithFullFilterTest.php
vendor/magento/magento2-base/dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Search/FilterMapper/StockStatusFilterWithGeneralFilterTest.php
vendor/magento/magento2-base/dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Search/FilterMapper/CustomAttributeFilterTest.php
vendor/magento/magento2-base/dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Search/FilterMapper/VisibilityFilterTest.php
vendor/magento/magento2-base/dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Adapter/Mysql/BaseSelectStrategy/BaseSelectAttributesSearchStrategyTest.php
vendor/magento/module-catalog-search/Model/Search/FilterMapper/VisibilityFilter.php
vendor/magento/module-catalog-search/Model/Search/FilterMapper/CustomAttributeFilter.php
vendor/magento/module-catalog-search/Model/Search/FilterMapper/TermDropdownStrategy/SelectBuilder.php
vendor/magento/module-catalog-search/Model/Adapter/Mysql/Filter/Preprocessor.php
vendor/magento/module-catalog-search/Model/Adapter/Mysql/BaseSelectStrategy/BaseSelectAttributesSearchStrategy.php
vendor/magento/module-catalog-search/Model/Adapter/Mysql/Aggregation/DataProvider/QueryBuilder.php
vendor/magento/module-catalog-search/Model/Adapter/Mysql/Aggregation/DataProvider/SelectBuilderForAttribute.php
vendor/magento/module-catalog-search/Test/Unit/Model/Adapter/Mysql/Aggregation/DataProvider/QueryBuilderTest.php
vendor/magento/module-inventory-catalog-search/Test/Integration/Model/Search/FilterMapper/TermDropdownStrategy/ApplyStockConditionToSelectOnDefaultStockTest.php
vendor/magento/module-inventory-catalog-search/Test/Integration/Model/Search/FilterMapper/TermDropdownStrategy/ApplyStockConditionToSelectTest.php
vendor/magento/module-inventory-catalog-search/Test/Integration/Model/Adapter/Mysql/Aggregation/DataProvider/ApplyStockConditionToSelectWithDefaultStockTest.php
vendor/magento/module-inventory-catalog-search/Test/Integration/Model/Adapter/Mysql/Aggregation/DataProvider/ApplyStockConditionToSelectTest.php
vendor/magento/module-inventory-catalog-search/Test/_files/clean_catalog_product_index_eav_table.php
Trying to add function
as testing my regex results into the regex however doesn't return any results:
grep -Ril 'catalog_product_index_eav.*function.*' vendor/
grep -Ril 'catalog_product_index_eav.*.*function.*' vendor/
Either I need to be able to to handle the regex better which is not returning anything (function
keyword is just something that I test with since it should be returning at least something) or better:
How do I forward the result names to further filter:
I want to do something like this then on those filtered file names:
grep -Ril 'catalog_product_index_eav' vendor/ | grep 'function`
OR
grep -Ril 'catalog_product_index_eav' vendor/ | grep 'function` [$filename]
CodePudding user response:
Suggesting to awk
script to AND
operation on RegExp (actually any logical expression of one or more RegExp).
awk '/regExp-pattern-1/ && /regExp-pattern-2/ {print FILENAME}' RS="&@&@&@&@" files-1 file-2 ...
The advantage of this approach: every file is scanned only once. And every file is scanned as a single record (grep
is scanning line by line).
The disadvantages: RegExp patterns in awk
are case sensitive. And awk
takes list of files only (no recursive folders).
As for pure grep
Suggesting to nest grep
commands.
grep -il "regExp-pattern-2" $(grep -irl "regExp-pattern-1" folder-path)