Reputation: 719
I'm trying to tail a log file and format the output into columns. This gives me what I want without tail:
cat /var/log/test.log | column -t -s "|"
How can I pipe the output of tail -f var/log/test.log
into column
?
EDIT: Here's an excerpt from the file. I'm manually adding the first line of the file so it could be used as the column headers, but I could format it differently if necessary.
timestamp|type|uri|referer|user_id|link|message
Feb 5 23:58:29 181d5d6339bd drupal_overlake: 1612569509|geocoder|https://overlake.lando/admin/config/development/configuration/config-split/add|https://overlake.lando/admin/config/development/configuration/config-split/add|0||Could not execute query "https://maps.googleapis.com/maps/api/geocode/json?address=L-054%2C%20US&language=®ion=US".
Feb 5 23:58:29 181d5d6339bd drupal_overlake: 1612569509|geocoder|https://overlake.lando/admin/config/development/configuration/config-split/add|https://overlake.lando/admin/config/development/configuration/config-split/add|0||Unable to geocode 'L-054, US'.
Upvotes: 3
Views: 1728
Reputation: 2733
Yes, column
need all final input to process text... but we can trick it: tail -f
is just "regular tail
run continuously, right? ツ
watch -n 1 "tail -n 20 myfile.log | column -t"
If you need to keep the first line (as header for instance), you can also do it cleverly:
watch -n 1 "(head -n1 && tail -n20) < users.csv | column -s, -t"
Source: https://avilpage.com/2023/01/pipe-tail-output-into-column.html (from SO' user Chillar Anand)
Upvotes: 0
Reputation: 781096
You can't do it with the -f
option to tail
. column
can't produce any output until it receives all its input, since it needs to calculate the number of rows and columns by examining all the input. tail -f
never stops writing, so column
doesn't know when it's done.
You can use
tail -n 100 test.log | column -t -s "|"
to format the last 100 lines of the log.
Upvotes: 2