9

I have a text log of computation which contains a line for each iteration. We track the computation with

tail -f log.txt

But the lines of log file are very long and the tail output is unreadable.

I've tried this

tail -f log.txt | head -c 50

but it shows only beginning of the first line, but not lines which are produced after.

How can I dynamically display only first 50 characters of newly added line to the log file?

Thank you

sivic
  • 533
  • 6
  • 12

2 Answers2

22

Use cut:

tail -f log.txt | cut -b 1-50
Kai Sternad
  • 22,214
  • 7
  • 47
  • 42
  • 1
    just remember that output will be buffered, so you may have to wait a while before anything is shown – Vitor Apr 30 '14 at 17:27
3

This is working for me:

tail -f log.txt | awk '{print substr ($0, 0, 50)}'
sivic
  • 533
  • 6
  • 12