サブフォルダがrules/resources
あるためというフォルダがありますA
。各サブフォルダーに。B
C
constraint.yaml
これで文字列を含むファイルが欲しいですgrep
。私は次のように使用しようとしています:constraint.yaml
assetType
grep
grep -rIih assetType rules/resources/
私は次のような結果を得ます。
assetType: cloudfunctions.googleapis.com/CloudFunction
assetType: cloudfunctions.googleapis.com/CloudFunction
assetType: cloudfunctions.googleapis.com/CloudFunction
assetType: cloudfunctions.googleapis.com/CloudFunction
assetType: cloudfunctions.googleapis.com/CloudFunction
assetType: bigquery.googleapis.com/Dataset
assetType: artifactregistry.googleapis.com/Repository
assetType: composer.googleapis.com/Environment
assetType: composer.googleapis.com/Environment
assetType: composer.googleapis.com/Environment
assetType: apigateway.googleapis.com/Gateway
assetType: apigateway.googleapis.com/Gateway
しかし、文字列を表示したくありませんassetType
。重複した値も削除する必要があります。希望の出力は次のとおりです。
cloudfunctions.googleapis.com/CloudFunction
bigquery.googleapis.com/Dataset
artifactregistry.googleapis.com/Repository
composer.googleapis.com/Environment
apigateway.googleapis.com/Gateway
ベストアンサー1
あなたのもの(使用しているためgrep
GNUであるように見え、すべて非標準GNU拡張です)がPCREサポートで構築されている場合は、次のことができます。grep
-r
-I
-h
grep -rIihPo 'assetType:\s*\K.*' rules/resources/
正規表現に一致するテキストを出力するために使用した場所では、一致で非表示にする-o
内容を指定するPerlに似た正規表現にo
切り替えます。-P
\K
K
重複した項目を整列して削除するパイプですsort -u
。