![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How do I get my script to monitor a new file using tail? | lstorm2003 | Shell Programming and Scripting | 4 | 06-06-2009 09:58 AM |
| Aix script to monitor when a file has been updated | elmesy | AIX | 2 | 03-19-2009 04:28 PM |
| Script to find file name for non matching pattern | sujoy101 | Shell Programming and Scripting | 5 | 03-31-2008 10:10 AM |
| File search for pattern - script | rahulrathod | Shell Programming and Scripting | 3 | 02-16-2007 04:03 AM |
| Find script with input pattern file | iguanathompson | Shell Programming and Scripting | 8 | 02-06-2006 06:23 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Script to monitor the pattern in the log file
hi All,
how to find a pattern in the log file & display the above and below line for example in the log file, i have many lines, whenever i search for "Category" it should display the above line with only few parameter like i want only the location name & department name Thu Jul 02 11:05:23 2009<location> noth amer</location><Site>ohioc</site><department>IT sales</department><country>UAT</country> Thu Jul 02 11:05:39 2009 ird: INFO: (pack) We have a Problem Record. pp_HPD: category, Type is invalid Thu Jul 02 11:05:39 2009 please enter the corrct details in the below code i'm able to get only the above line Logn="file name" for log in $Log do cat $log |sed -n -e'/Category/{x;1!p;}' -e h |grep "`date +%a' '%b' '%d`" >> $Logn/System_Log done but i'm not getting the custom parmater from the above line |
|
||||
|
use `date +%a' '%b' '%d` once is enough. don't put it together with grep. you don't want to call date everytime sed pass a line to grep.
Code:
datepattern=`date +%a' '%b' '%d` sed .... | grep $datepattern Code:
awk 'BEGIN{
datepattern = "^"strftime("%a %b %d",systime())
}
/category/{
if (x ~ datepattern){
scrape(x)
}
getline l
if (l ~ datepattern){
# do something with below line
}
}
{
x=$0
}
function scrape(s){
o=s
gsub(/.*<location>/,"",o)
gsub(/<\/location>.*/,"",o)
print "location: ",o
gsub(/.*<department>/,"",x)
gsub(/<\/department>.*/,"",x)
print "dept: "x
}' file
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|