Solved

nawk regular expression issue

Posted on 2003-11-05
3
325 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

749 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