1

This seems to come up a few times. I'll be trying to spot differences in logs with repeating cycles. For example:

start
1
2
3
end
start
1
2
4
3
end

Rather than scrolling through pages of terminal output it would be nice to have some structure to the log. The tool watch can run a command at some interval, and even highlight changes with -d. Is there an easy way to split up the output from a program that prudces the above into blocks between start/end?

Just viewing changes in real-time from a fixed line within the cycle would be nice so I could spot changes. Being able to scroll through cycles would be great too.

2 Answers 2

0

Wrote something small in the meantime. It's not great but gets the job done.

https://github.com/pknowles/watch_cycles

cat log.txt | ./watch_cycles "start"

Shows, for example:

page 2/2
start
1
2
4
3
end

Arrow keys scroll to previous pages.

0

A new utility pw (PipeWatch) has a feature for exactly this.

tail -f log.txt | pw

pw pumps data through an internal FIFO buffer, from which snapshots are taken, displayed, and pushed into a 20-screen-deep snapshot history, which can easily be visited using the up/down arrow keys or CtrlP and CtrlN.

By default, snapshots are taken every 10 seconds, or whenever there is a 1 second read timeout, and of course these timeouts can be adjusted.

The trigger feature causes the unchanging parts of repeating patterns to freeze on the screen. You can see this in the demo video.

However, you can easily put pw into trigger mode, using commands similar to Vi searching: /pattern and ?pattern. In trigger mode, the display updates whenever a match occurs against one or more lines in the FIFO. There is a lot more to it.

You can specify triggers before you start the program like this.

# trigger: match foo on line 1, bar on line 3
pw -e /foo -e 3/bar

If you have your triggers and other settings set up the way you like them, you can save the session with :s filename, and recall with pw -f filename; the session has your filters and triggers, plus display settings like the configuration of vertical splits. The file just contains /, ? and : (colon) commands, which you can easily edit to adjust.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.