开发者

Record Terminal output?

Im using a cool program in terminal but it's pre-compiled... Luckily all I need is the output of this system, but the way I need it is tricky... I need it to run normally but output the last line of text in the window to a text file. I jabs been looking around but people only make it so that I can log the whole thing, not just the last line.

it is a compiled unix executable that can't be r开发者_高级运维un with something like that because it needs to keep running and won't stop until stopped, and that didn't work


Use tail to get only the last line:

cool-program | tail -n 1 > text-file

If cool-program runs (and outputs) forever, redirect its output and tail then:

cool-program > log
# Later, when you're interested in the current last line:
tail -n 1 log


You can use the tail command to only capture the last n lines of a file or a stream. For example, to run ./myProgram but only display the last line of output:

./myProgram | tail -n 1

This pipes (|) the output of your program into the input of tail, which discards everything except the last n lines.

To save that output to a file instead, you can redirect (>) tail's output to a file:

./myProgram | tail -n 1 > out.txt
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜