<html><font size="2">Saul,<br><br>You should add END between the scopes, such as: <br><br>awk '/pattern/ { nlines++ } END {print nlines}' file<br><br>... works with gnu AWK<br><br>Jack Pope<br></font><div><font size="2"> </font></div>
<blockquote style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px"><font face="Tahoma" size="2">-----Original Message-----<br><b>From:</b> canito@dalan.us [mailto:canito@dalan.us]<br><b>Sent:</b> Friday, December 6, 2013 03:09 PM<br><b>To:</b> tclug-list@mn-linux.org<br><b>Subject:</b> [tclug-list] Count Number of Matched Patterns<br><br></font>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 -test
PATTERN=$1
egrep -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" ]; then
Thanks in advanced!
Saul David Alanis
_______________________________________________
TCLUG Mailing List - Minneapolis/St. Paul, Minnesota
tclug-list@mn-linux.org
http://mailman.mn-linux.org/mailman/listinfo/tclug-list
</blockquote>
</html>