I know there are a lot of different threads already like this, but nothing I can find seems to explain well enough exactly what I’m trying to do.
Basically I want to have a shell script that just goes through a text file, line by line, and searches for the words “Error” or “Exception”. Whenever it comes across those words it would record the line number so I can later shoot the text file off in an email with the problem lines.
I’ve seen a lot of stuff that explains how to loop through a text file line by line, but I don’t understand how I can run a regular expression on that line, because I’m not sure exactly how to use regular expressions with a shell script and also what variable each line is being stored in…
If anybody can clarify these things for me I would really appreciate it.
There are numerous tools that automatically loop thru files. I would suggest a simple solution like:
use
man grepto understand the options I’m supplying.From `man bash
I hope this helps.