Solved

nawk regular expression issue

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 146
WinWaitActive parameters 12 31
abstract class with all non abstract mentods 6 80
how to split multiple lines delimiter : 8 109
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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. …
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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