script to tail file; problem with awk and special characters

Trying to use code that I found to send only new lines out of a log file by doing:

while :; do
temp=$(tail -1 logfile.out)
awk "/$last/{p=1}p" logfile.out  #pipe this to log analyzer program
last="$temp"
sleep 10
done

Script works fine when logfile is basic text, but when it contains characters that have brackets and slashes, the awk command has issues:

awk: fatal: Invalid range end: /[15C8:01E6-0258] 01/

Here is sample data in log:

[15C8:01EB-1DF8] 01/24/2012 08:03:43 AM Open session 
[15C8:01EB-0310] 01/24/2012 08:03:43 AM  Closed session 
[11A8:000F-06F4] 01/24/2012 08:03:44 AM  Router: Message 0047BCE8 delivered to
[15C8:01EB-1660] 01/24/2012 08:03:44 AM  Opened session 
[15C8:01E6-0258] 01/24/2012 08:03:44 AM  Closed session for 

I have tried different ways of putting quotes around the last variable, but does not work or breaks script in different way. Any awk experts have suggestions?

Thx. Moo.

Another way :

Last=0
while :
do
    Line=$(wc -l < moo.txt)
    awk "NR>$Last {p=1}p" moo.txt #pipe this to log analyzer program
    Last=$Line
    sleep 10
done

Jean-Pierre.

1 Like

thx jean-Pierre. I added the if statement to your code to handle if log file gets truncated/rolled/etc....

Last=0 
while : do     
Line=$(wc -l < moo.txt)
    if [ $Line -lt $Last ]     
then          
Last=0     
fi
    awk "NR>$Last {p=1}p" moo.txt #pipe this to log analyzer program     
Last=$Line     
sleep 10 
done