0

I have a log file in which I need to check if there are any error messages, if there are, extract the error message to another file.

Like this I may have error file for the different file have different log patterns. So how can I search matching pattern using a variable?

As I want to create one generic .sh file for all log files. Suppose I have one file in which I want to search to pattern and print in another file $pat1="ERROR MESSAGE" $pat2="RAISE_ERROR_SEEN". I want all lines from file b/w these two patterns.

Using variable only.

slm
  • 369,824

2 Answers2

0

Try this,

 awk "/""$pat1""/,/""$pat2""/" test.log | grep -v "$pat3" > Error.bk
  • will print the context between $pat1 and $pat2
  • Since we have space in the first variable, use double quotes twice.
Siva
  • 9,077
0

in a more simple way:

grep -e "$pat1\|$pat2" filename > resultfile