<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body >I think most cli utilities support using -- (two dashes) to signify the end of the commands options. <div><br><div>Example </div><div><br></div><div>$ grep -- -t file.txt </div><div><br></div></div><br><br><br>-------- Original message --------<br>From: canito@dalan.us <br>Date: 12/06/2013 2:09 PM (GMT-06:00) <br>To: tclug-list@mn-linux.org <br>Subject: [tclug-list] Count Number of Matched Patterns <br> <br><br>In the process of writing a script which I would like to count the <br>number matched patterns (command line parameters).<br><br>The issue I am running into using grep is that the string has a dash <br>in front, and it throws an error.<br><br>E.g:<br><br>./script -test<br><br>PATTERN=$1<br><br>egrep -ic $PATTERN --> egrep: invalid option -- 't'<br><br>awk and egrep work using a file, but not on a variable:<br><br>EXAMPLE=`awk '/test/ { nlines++ } {print nlines}' $PATTERN`<br><br>awk: cmd. line:1: fatal: cannot open file `-test' for reading (No such <br>file or directory)<br><br>I know using and if command works, so am I just over doing it? What am <br>I doing wrong?<br><br>if [[ $PATTERN == "-test" ]; then<br><br>Thanks in advanced!<br><br>Saul David Alanis<br><br><br><br><br>_______________________________________________<br>TCLUG Mailing List - Minneapolis/St. Paul, Minnesota<br>tclug-list@mn-linux.org<br>http://mailman.mn-linux.org/mailman/listinfo/tclug-list<br></body>