Solved

nawk regular expression issue

Posted on 2003-11-05
3
326 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Accepted Solution

by:
glassd earned 50 total points
ID: 9690197
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
ID: 9690198
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
ID: 9695073
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

717 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