sivic
sivic

Reputation: 529

Tail only first few character of a line

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

Upvotes: 9

Views: 6878

Answers (2)

sivic
sivic

Reputation: 529

This is working for me:

tail -f log.txt | awk '{print substr ($0, 0, 50)}'

Upvotes: 3

Kai Sternad
Kai Sternad

Reputation: 22850

Use cut:

tail -f log.txt | cut -b 1-50

Upvotes: 23

Related Questions