Tailing and counting lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Tailing and counting lines
# 1  
Old 09-15-2013
Tailing and counting lines

Code:
tail -f /var/log/syslog | egrep -c FATAL

is there a way to do the above and actually have the number of lines matching the pattern increment as it is logged to the log file?

for instance, when you invoke a command like the one i just posted, you'll not get the total lines unless you do something like this, which isn't what i want:

Code:
Code:
egrep -c FATAL /var/log/syslog

I want to be able tail a live log and instead of seeing the lines, i want an incrementing number which will represent the number of entries found matching the pattern i specified.

Last edited by SkySmart; 09-15-2013 at 05:29 PM..
# 2  
Old 09-15-2013
Here is what I came up with:
In one terminal window run this:
Code:
tail -f /var/log/syslog > /tmp/syslog.tmp

In another run this:
Code:
while true; do clear; grep -c FATAL /tmp/syslog.tmp; sleep 1; done

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 09-15-2013
Quote:
Originally Posted by bartus11
Here is what I came up with:
In one terminal window run this:
Code:
tail -f /var/log/syslog | tee /tmp/syslog.tee > /dev/null

In another run this:
Code:
while true; do clear; grep -c FATAL /tmp/syslog.tee; sleep 1; done

i was hoping to avoid having to write to disk. i think some implementation of awk can probably do this (at least that's what i'm wishing for).
# 4  
Old 09-15-2013
Code:
tail -f /var/log/syslog |
awk '/FATAL/ {print ++c}'

Or overprint with
Code:
{printf "\r"++c}

This User Gave Thanks to MadeInGermany For This Post:
# 5  
Old 09-15-2013
Quote:
Originally Posted by MadeInGermany
Code:
tail -f /var/log/syslog |
awk '/FATAL/ {print ++c}'

Or overprint with
Code:
{printf "\r"++c}

this is more like it! thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Counting # of lines

Counting number of lines: sp I am trying to figure out a script to count the number of text files in cywig and have it give me a number (as the answer) any help would be appreciated. I am new here, so be gentle :D (3 Replies)
Discussion started by: unicksjp
3 Replies

2. Shell Programming and Scripting

sed counting lines

Hi, I'm using the command: sed -n '$=' $1 on a sh script on AIX. This script is used to count the number of lines of files. If the file has no lines at all the command doesn't return nothing. I need the command to return 0 when the file has no lines at all. How can I achieve this? Best... (5 Replies)
Discussion started by: jppedroso
5 Replies

3. UNIX for Advanced & Expert Users

Delete # of Lines after counting

I'm trying to write a script to clean up log file automatically when it reaches 1000 lines. I can't get this to work..can some help me please :) Server: SunOS 5.8 Generic_117350-53 sun4u sparc SUNW,Netra-T12 #!/bin/ksh #file reference file=`echo "$HOME/support/moe/b.tc"` #linecount... (7 Replies)
Discussion started by: moe458
7 Replies

4. Shell Programming and Scripting

Counting lines for each application

Hi All, I have a output that suppose to be like this (see below please) App : Line counts === ================== AAA: 100 BBB: 201 CCC: 137 DDD: 32 EEE: 55 for i in `ps -ef | grep App`; do print $i; done This only shows App : === (12 Replies)
Discussion started by: Beginer0705
12 Replies

5. Shell Programming and Scripting

Counting similar lines

Hi, I have a little problem with counting lines. I know similar topics from this forum, but they don't resolve my problem. I have file with lines like this: 2009-05-25 16:55:32,143 some text some regular expressions ect. 2009-05-25 16:55:32,144 some text. 2009-05-28 18:15:12,148 some... (4 Replies)
Discussion started by: marcinnnn
4 Replies

6. Shell Programming and Scripting

Counting lines between two patterns

Hi Guys, I have a file as follows: wwe khfgv jfo wwe jhgfd wwe wwe hoaha hao lkahe wwe (13 Replies)
Discussion started by: npatwardhan
13 Replies

7. Shell Programming and Scripting

counting the number of lines - again

Hi all, I use bash shell and I have a problem with wc. I would like to determine the number of lines in a file so I do wc -l filename but I don't want to get the filename again I just would like to have the number of lines and use it in a variable. Can anybody help? Thank you, (7 Replies)
Discussion started by: f_o_555
7 Replies

8. Shell Programming and Scripting

displaying/ counting lines

I have a file called xx with the env redirected into it 5 times: env >> xx env >> xx env >> xx env >> xx env >> xx I have to read an input file (here: xx) and look for occurrences of the current user who is executing this script. Once finding an occurrence of the username I have to take that... (2 Replies)
Discussion started by: aga
2 Replies

9. Linux

counting the number of lines

Hello, I have afile which begins with a few urls on multiple lines and then there is listing of some information on separate lines. The listing begins with the word Name on a given line followed by teh actual list. I want to count the number of lines in this file after the line having... (6 Replies)
Discussion started by: nayeemmz
6 Replies

10. UNIX for Dummies Questions & Answers

Counting lines and files

Hi experts, First of all thanks for all your help. How can i count the lines within a text file and send this number to another text file? And by the way how can i count the number of files inside a tape ("/dev/rtp") that as one pattern (Ex. "/CTA/") and send this number to a text file? I... (6 Replies)
Discussion started by: jorge.ferreira
6 Replies
Login or Register to Ask a Question