Solved

nawk regular expression issue

Posted on 2003-11-05
3
322 Views
Last Modified: 2013-12-26
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!
0
Comment
Question by:p1800volvo
3 Comments
 
LVL 7

Accepted Solution

by:
glassd earned 50 total points
Comment Utility
Strange. I am running Solaris9 and nawk is able to use \/ as a litral /.

However:

Normally a period (.) represents any single character, so /Netscape.7.1/ should match.
0
 

Expert Comment

by:rishisk
Comment Utility
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

0
 
LVL 1

Author Comment

by:p1800volvo
Comment Utility
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.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now