analyse a shell script
Hi all,
I have a file with patterns like the one hereafter, patterns begin and end with ======, there are many lines inside a pattern. It's a log and what I want to do is to check every pattern to look if the string ERROR exists and if so print that string and the date, hour and Reference contained in the pattern. I need help to write the script shell. Thanks in advance Consty ====== 05/02/2007 04:51:02 [8714]: abdndala.c01.07: SAMS can not be sent, TYPE=DOUBE, STATE: 342184546 (slipt 6,Entity:ANY). ERROR: 4685 Reference :=172910706273 absolute MM :=)(A1225:clAd=0000)(29746:messi :=624020100762629)(2747:hel_lang=3)(K2749: sams_id=398) ====== |
try to read some information about sed and grep commands. they are great text filtering and searching tools. google and sed and grep and you'll get the results you need. post the log file if you can.
the best i can think off for now if trying the following: Code:
cat error file | grep ERROR* |
The problem with grep is that it's exclusively line-based. He needs to know the date and time, but these are contained on a line that comes before the one that tells him if he needs to keep that information at all. This is a situation where Perl comes in really handy. Not knowing the fully syntax of the log file, here's a simple script I came up with:
Code:
#!/usr/bin/env perl Code:
====== |
This might get you started.
Print paragraphs that contain ERROR: Code:
sed -e '/./{H;$!d;}' -e 'x;/ERROR/!d;' my_file Some people might tell you to use perl. If you need more info for sed: post more input and intended output. Good link for sed: http://www.linuxquestions.org/bookmarks/tags/sed |
Quote:
Code:
#!/bin/bash |
All times are GMT -5. The time now is 08:02 AM. |