如何过滤掉./gradlew project:dependencies命令的特定部分? [英] How to filter out a certain portion of ./gradlew project:dependencies command?

查看:71
本文介绍了如何过滤掉./gradlew project:dependencies命令的特定部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的build.gradle文件具有您的常规 depndencies 块,就像这样..

Our build.gradle files have your normal depndencies block, like so..

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 管道,就像这样

I want to get ALL the lines that do not start with the | character. It just so happens that all these lines also end with (*) characters, so I add a sed pipe, like so

./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

这正是我想要的,除了该行缺失

which is exactly what I want, except that this line is missing

com.myco.cms:cms-service-client:1.0.145

因为,因此恰好以(*)字符结尾.什么是更好的sed(或awk)表达式,所以我得到了

because it so happens to end with the (*) characters. What is a better sed (or awk) expression so I get

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文件而不是./gradlew project:dependencies ,因为我没有该命令):

Seems like this might be what you want (using cat file instead of ./gradlew project:dependencies since I don't have that command):

$ 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

这篇关于如何过滤掉./gradlew project:dependencies命令的特定部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆