Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 296
sivic Avatar asked Apr 30 '14 17:04

sivic


People also ask

How do you tail a certain number of lines?

The tail command is used to print last 10 lines of a file by default. However, like the head command, we can change the number number of lines to be displayed by using the -n option, or just -<number> , to display a different number of lines as specified.

Which commands will show the first 5 characters of each line in a file?

where head -c5 is the right command to get the first 5 characters from the string. Save this answer. Show activity on this post. And how exactly does this print the first 5 chars of every line of sample.

How do you display the first 10 characters from each line of a file?

The head command is used to display the first lines of a file. By default, the head command will print only the first 10 lines. The head command ships with the coreutils package, which might be already installed on our machine.

Which command shows first 3 line of file?

To look at the first few lines of a file, type head filename, where filename is the name of the file you want to look at, and then press <Enter>. By default, head shows you the first 10 lines of a file. You can change this by typing head -number filename, where number is the number of lines you want to see.


1 Answers

Use cut:

tail -f log.txt | cut -b 1-50
like image 110
Kai Sternad Avatar answered Sep 28 '22 04:09

Kai Sternad