简体   繁体   中英

How to grep on Sbt output?

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

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

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

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

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

 ./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. You should quote grep pattern
  2. You should use fixed string search

Try this command:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM