Bash 如何筛选出./gradlew project:dependencies命令的特定部分?(第二版)
我发布了一段时间,并实现了公认的答案。然而,它似乎给了我错误的信息 我有以下(简化的)Bash 如何筛选出./gradlew project:dependencies命令的特定部分?(第二版),bash,shell,gradle,awk,sed,Bash,Shell,Gradle,Awk,Sed,我发布了一段时间,并实现了公认的答案。然而,它似乎给了我错误的信息 我有以下(简化的)build.gradle文件 dependencies { implementation("com.myco.security:security-service-client:1.0.199") } 当我运行命令时 $ ./gradlew :project:dependencies | tee deps.txt 我在deps.txt文件中看到了以下内容,缩写为仅显示我想要的工件 compileCla
build.gradle
文件
dependencies {
implementation("com.myco.security:security-service-client:1.0.199")
}
当我运行命令时
$ ./gradlew :project:dependencies | tee deps.txt
我在deps.txt
文件中看到了以下内容,缩写为仅显示我想要的工件
compileClasspath - Compile classpath for source set 'main'.
+--- com.myco.security:security-service-client:1.0.199 -> 1.0.148
+--- com.myco.security:security-service-client:1.0.148 (*)
default - Configuration for default artifacts.
+--- com.myco.security:security-service-client:1.0.199 -> 1.0.148
+--- com.myco.security:security-service-client:1.0.148 (*)
+--- com.myco.security:security-service-client:1.0.148 (*)
implementation - Implementation only dependencies for source set 'main'. (n)
+--- com.myco.security:security-service-client:1.0.199 (n)
+--- com.myco.security:security-service-client:1.0.148 (n)
runtimeClasspath - Runtime classpath of source set 'main'.
+--- com.myco.security:security-service-client:1.0.199 -> 1.0.148
testCompileClasspath - Compile classpath for source set 'test'.
+--- com.myco.security:security-service-client:1.0.199 -> 1.0.148
+--- com.myco.security:security-service-client:1.0.148 (*)
testRuntimeClasspath - Runtime classpath of source set 'test'.
+--- com.myco.security:security-service-client:1.0.199 -> 1.0.148
+--- com.myco.security:security-service-client:1.0.148 (*)
现在,我的build.gradle
文件中的依赖项出现了多次。现在,如果我在我原来的链接帖子中应用这个答案,我会得到
com.myco.security:security-service-client:1.0.199
com.myco.security:security-service-client:1.0.148
作为工件,只需以下内容,这就是我想要匹配我的build.gradle
文件中的依赖项的内容
com.myco.security:security-service-client:1.0.199
如何改进链接帖子中的awk
命令?瞧
cat deps.txt | awk '/^\+.*com\.myco/ && !seen[$2]++{print $2}' | some_other_cmd
应该只给我
com.myco.security:security-service-client:1.0.199
您可以使用此awk:
awk -F '[: ]+' -v OFS=: '/^\+.*com\.myco/ && !seen[$2,$3]++{print $2, $3, $4}' deps.txt
详细信息:
- 使用
我们在空格或冒号上拆分列-F'[:]+'
- 使用
我们使用冒号作为输出文件分隔符-vofs=:
使用依赖项的seen[$2,$3]
作为数组键group:module
打印打印$2、$3、$4
组:模块:版本
com.myco.security:security-service-client:1.0.199