Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 如何筛选出./gradlew project:dependencies命令的特定部分?(第二版)_Bash_Shell_Gradle_Awk_Sed - Fatal编程技术网

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
    打印
    组:模块:版本

谢谢@anubhava,你这个男人!这很有魅力。总有一天我会学好awk的。
com.myco.security:security-service-client:1.0.199