Saul,

You should add END between the scopes, such as: 

awk '/pattern/ { nlines++ } END {print nlines}' file

... works with gnu AWK

Jack Pope

-----Original Message-----
From: canito at dalan.us [mailto:canito at dalan.us]
Sent: Friday, December 6, 2013 03:09 PM
To: tclug-list at mn-linux.org
Subject: [tclug-list] Count Number of Matched Patterns

In the process of writing a script which I would like to count the number matched patterns (command line parameters).The issue I am running into using grep is that the string has a dash in front, and it throws an error.E.g:./script -testPATTERN=$1egrep -ic $PATTERN --> egrep: invalid option -- 't'awk and egrep work using a file, but not on a variable:EXAMPLE=`awk '/test/ { nlines++ } {print nlines}' $PATTERN`awk: cmd. line:1: fatal: cannot open file `-test' for reading (No such file or directory)I know using and if command works, so am I just over doing it? What am I doing wrong?if [[ $PATTERN == "-test" ]; thenThanks in advanced!Saul David Alanis_______________________________________________TCLUG Mailing List - Minneapolis/St. Paul, Minnesotatclug-list at mn-linux.orghttp://mailman.mn-linux.org/mailman/listinfo/tclug-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.mn-linux.org/pipermail/tclug-list/attachments/20131206/da73dde8/attachment.html>