我们的build.gradle文件具有您的常规depndencies
块,如下所示。
dependencies {
compile("com.myco.service:service-discovery:+")
compile("com.myco.common:some-common:1.0.84")
compile("com.myco.cms:cms-service-client:1.0.145")
compile("com.myco.stats:some123-stats-service-client:1.0.140")
...
}
我运行它来获取依赖树
$ ./gradlew project:dependencies | grep com\.myco | sort | uniq
并得到
+--- com.myco.canam:canam:0.1.4
+--- com.myco.cms:cms-service-client:1.0.145 (*)
+--- com.myco.common:some-common:1.0.84
+--- com.myco.crm:crm.ansira:0.0.1
+--- com.myco.somehtml:somehtmlcleaner:0.0.1
| +--- com.myco.common:some-common:1.0.79 -> 1.0.84 (*)
| +--- com.myco.security:security-service-client:1.0.107 -> 1.0.134 (*)
| +--- com.myco.common:some-common:1.0.58 -> 1.0.84 (*)
| +--- com.myco.common:some-common:1.0.80 -> 1.0.84 (*)
我想获得所有不以
|
字符开头的行。碰巧所有这些行都以(*)
字符结尾,所以我添加了sed
管道,如下所示./gradlew project:dependencies | sed 's/^.* //' | grep com\.myco | sort | uniq
并得到
com.myco.canam:canam:0.1.4
com.myco.common:some-common:1.0.84
com.myco.crm:crm.ansira:0.0.1
com.myco.somehtml:somehtmlcleaner:0.0.1
正是我想要的,但缺少此行
com.myco.cms:cms-service-client:1.0.145
,因为恰好以
(*)
字符结尾。什么是更好的sed(或awk)表达式,所以我得到了com.myco.canam:canam:0.1.4
com.myco.cms:cms-service-client:1.0.145
com.myco.common:some-common:1.0.84
com.myco.crm:crm.ansira:0.0.1
com.myco.somehtml:somehtmlcleaner:0.0.1
最佳答案
似乎这可能是您想要的(因为我没有该命令,所以使用cat file
而不是./gradlew project:dependencies
):
$ cat file | awk '/^\+.*com\.myco/ && !seen[$2]++{print $2}'
com.myco.canam:canam:0.1.4
com.myco.cms:cms-service-client:1.0.145
com.myco.common:some-common:1.0.84
com.myco.crm:crm.ansira:0.0.1
com.myco.somehtml:somehtmlcleaner:0.0.1
关于shell - 如何过滤掉./gradlew project:dependencies命令的特定部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57700382/