Link to home
Start Free TrialLog in
Avatar of p1800volvo
p1800volvo

asked on

nawk regular expression issue

I have a bit of code in nawk that I would like some help with. It is searching a file for User Agent strings and giving me a count of each login by browser version. The problem is when I search on Netscape/7.1 it bombs out since the string has a / character. I have tried a leading \ with no help. Here is the code;

nawk '
   found=0
     /4.79/ { count6++;found=1 }
    /Netscape/7.1/ {count7++;found=1 }
   { if(found == 0) countu++ }
END{
     print "Netscape 4.79",count6
   Print "Netscape 7.1", count7
   print "Unknown",countu
}' > $1.uaout

What character should I use to make nawk ignore the / character in Netscape/7.1? Searching on 7.1 is not an option due to the number of records with this string as part of a the time field.

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of glassd
glassd

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rishisk
rishisk

Your approach is correct. The one statement that will cause a problem is Print (Capitalized 'P') in

Print "Netscape 7.1", count7

Change this to

print "Netscape 7.1", count7

Avatar of p1800volvo

ASKER

glassd has it! That did it. Thanks again!

Credit should also be given to rishisk for his answer since the "P" was a mistake that prevented it from completing in later steps.