我们的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发布于 2019-08-28 21:58:07
这似乎是您想要的(使用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.1https://stackoverflow.com/questions/57700382
复制相似问题