我有一個grep特定正則運算式找到的過濾檔案串列,但想使用該過濾檔案串列的結果來進一步處理grep這些結果。
僅針對檔案名過濾 Magento 2 代碼庫:grep -Ril(-i 僅因為我嘗試對正則運算式使用額外過濾)
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
嘗試將function作為測驗我的正則運算式結果添加到正則運算式中但是不會回傳任何結果:
grep -Ril 'catalog_product_index_eav.*function.*' vendor/
grep -Ril 'catalog_product_index_eav.*.*function.*' vendor/
要么我需要能夠更好地處理不回傳任何東西的正則運算式(function關鍵字只是我測驗的東西,因為它應該至少回傳一些東西)或者更好:
如何轉發結果名稱以進一步過濾:
我想對那些過濾的檔案名做這樣的事情:
grep -Ril 'catalog_product_index_eav' vendor/ | grep 'function`
OR
grep -Ril 'catalog_product_index_eav' vendor/ | grep 'function` [$filename]
uj5u.com熱心網友回復:
建議對 RegExp (實際上是一個或多個 RegExp 的任何邏輯運算式)進行awk腳本操作。AND
awk '/regExp-pattern-1/ && /regExp-pattern-2/ {print FILENAME}' RS="&@&@&@&@" files-1 file-2 ...
這種方法的優點是:每個檔案只掃描一次。并且每個檔案都被掃描為單個記錄(grep逐行掃描)。
缺點:RegExp 模式awk區分大小寫。并且awk只獲取檔案串列(沒有遞回檔案夾)。
至于純grep
建議嵌套grep命令。
grep -il "regExp-pattern-2" $(grep -irl "regExp-pattern-1" folder-path)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/432909.html
上一篇:拆分文本和數字
下一篇:正則運算式生成動態sql
