如何在Sbt输出上进行grep?

时间:2020-12-12 19:29:52

I want to run grep on sbt output, but can't find a way to do it.

我想在sbt输出上运行grep,但找不到办法。

Say, if I run Sbt command ./sbt dependency-tree, it will output:

比方说,如果我运行Sbt命令./sbt依赖树,它将输出:

[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Resolving org.slf4j#slf4j-api;1.7.5 ...
[info] Resolving org.scala-lang#scala-compiler;2.10.4 ...
[info]   | +-org.slf4j:slf4j-api:1.6.4
[info]   +-org.apache.commons:commons-dbcp2:2.0
[info]   | +-org.apache.commons:commons-pool2:2.2
[info]     +-org.scalaz:scalaz-core_2.10:7.0.6 [S]
[info]   +-org.scalaz:scalaz-core_2.10:7.0.6 [S]
[info]   | +-org.slf4j:slf4j-api:1.7.6 (evicted by: 1.7.7)
[info]   | +-org.slf4j:slf4j-api:1.7.7
[info]   +-org.slf4j:jul-to-slf4j:1.7.7
...

I want to run grep org.slf4j:jul-to-slf4j:1.7.7 to filter if this library is used in this project.

我想运行grep org.slf4j:jul-to-slf4j:1.7.7来过滤这个项目中是否使用了这个库。

But I tried: ./sbt dependency-tree | grep org.slf4j:jul-to-slf4j:1.7.7, which is not work and reports some errors from sbt.

但我试过:./ sbt dependency-tree | grep org.slf4j:jul-to-slf4j:1.7.7,这不起作用并从sbt报告一些错误。

I can save the output to a file, then grep on the file, like:

我可以将输出保存到文件,然后grep文件,如:

 ./sbt dependency-tree > a.txt
 cat a.txt | grep org.slf4j:jul-to-slf4j:1.7.7

Which works but not convenient.

哪个有效但不方便。

Is there any better command to do it?

有没有更好的命令呢?

1 个解决方案

#1


  1. You should quote grep pattern
  2. 你应该引用grep模式

  3. You should use fixed string search
  4. 您应该使用固定字符串搜索

Try this command:

试试这个命令:

./sbt dependency-tree | grep -F 'org.slf4j:jul-to-slf4j:1.7.7'

#1


  1. You should quote grep pattern
  2. 你应该引用grep模式

  3. You should use fixed string search
  4. 您应该使用固定字符串搜索

Try this command:

试试这个命令:

./sbt dependency-tree | grep -F 'org.slf4j:jul-to-slf4j:1.7.7'