bash - 仅将 STDOUT 的最后一行重定向到文件

标签 bash shell unix

我正在编译 Scala 代码并将输出控制台输出写入文件。我只想将 STDOUT 的最后一行保存在文件中。这是命令:

scalac -Xplugin:divbyzero.jar Example.scala >> output.txt

scalac -Xplugin:divbyzero.jar Example.scala 的输出是:

helex@mg:~/git-repositories/my_plugin$ scalac -Xplugin:divbyzero.jar Example.scala | tee -a output.txt
You have overwritten the standard meaning
Literal:()
rhs type: Int(1)
Constant Type: Constant(1)
We have a literal constant
List(localhost.Low)
Constant Type: Constant(1)
Literal:1
rhs type: Int(2)
Constant Type: Constant(2)
We have a literal constant
List(localhost.High)
Constant Type: Constant(2)
Literal:2
rhs type: Boolean(true)
Constant Type: Constant(true)
We have a literal constant
List(localhost.High)
Constant Type: Constant(true)
Literal:true
LEVEL: H
LEVEL: H
okay
LEVEL: H
okay
false
symboltable: Map(a -> 219 | Int | object TestIfConditionWithElseAccept2 | normalTermination | L, c -> 221 | Boolean | object TestIfConditionWithElseAccept2 | normalTermination | H, b -> 220 | Int | object TestIfConditionWithElseAccept2 | normalTermination | H)
pc: Set(L, H)

我只想在输出文件中保存 pc: Set(L, H) 而不是其余部分。在哪个命令的帮助下我可以实现我的目标?

最佳答案

只需通过 tail -n 1 将标准输出传输到您的文件

关于bash - 仅将 STDOUT 的最后一行重定向到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4821731/

相关文章:

linux - bash:如何仅传输/复制文件名以分隔相似的文件?

bash - Supervisord haproxy重新加载无法正常工作

Chmod 和相对权限(在 C 中)

arrays - sh + 如何在 sh 中使用数组来打印数组中的所有值

php - 使用 PHP 关闭服务器

python - 获取当前打开文件的完整路径

linux - 有没有办法计算目录的 inode ?

c - 多管道 C 程序不起作用

bash - 如何使用 ls 在 Unix 中查找一组特定日期的文件

ruby - 为三列中的每一列中的每个地址添加一行