I am working to parse apache logs in Common Format in realtime so that I monitor them while I work. "tail -F /var/log/apache2/access.log" works but provides more than I need. "awk '{print $1 " " $2 " " $3 " " $4 " "}'access.log " gives the parts I need but of course runs x1 and I do not know the bash well enough (yet!) to loop on something like file change etc. So I would like to pipe "|" the output of the tail expression above to the awk expression above. Also, I would like for this output to print last line of the access.log at the top of the screen, not the bottom.

  • 1
    Have you tryed the obvious tail -F /var/log/apache2/access.log | awk '{print $1 " " $2 " " $3 " " $4 " "}' ? – JucaPirama Apr 10 '19 at 18:16
  • Yes, thank you I did, but whereas the "tail" expression produces the last 10 lines of the access.log file, piping to the "awk" produces no output. AWK syntax ( awk options 'selection_criteria {action }' input-file > output-file ) seems to suggest the input_file might be a place where the tail expression could be inserted, but I have no idea how. Simply piping the tail expression to " awk '{print}' " likewise makes no output. – Dahere Apr 11 '19 at 16:21
  • I tested here (both with tail -f and tail -F and was able to achieve success. The awk version is gwak. – JucaPirama Apr 11 '19 at 17:06
  • I googled a little and found superuser.com/questions/742238/piping-tail-f-into-awk: tells about the terminal buffer, and how to avoid this behaviour. – JucaPirama Apr 11 '19 at 17:13
  • @JucaPirama I tried 'unbuffer' as per the link, however, it didn't work for some reason. But, now knowing of the buffer issue, I simply issue the 'tail' command as per your first comment and then reload the index web page a couple of times to prime it, so to speak. So I'll call the question answered, or at least resolved. Thank You. – Dahere Apr 16 '19 at 23:50

Your Answer

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

Browse other questions tagged or ask your own question.