Grep Basics – But, Are You Sure You Want to Use Grep?

Keep in mind: many things you want to do in grep you can do in awk.  Or, maybe there is just a better way.  I learned grep early on and have been forcing it to do things it wasn’t really designed to do, so here I will actually be listing solutions using other tools – tools that may be better designed for the task at hand.

Display Line Number of a Match

awk:

awk '/textstring/ {print FNR}' textfile

sed:

sed -n '/pattern/=' filename