|
Prev: recursively searching directories, filtering some file extensions and processing found files
Next: script provides input for executable
From: Maxwell Lol on 29 Mar 2008 06:21 explor <bhaveshah(a)gmail.com> writes: > Hi Gurus, > [snip] I think you have line wrapping. How many lines are the following? > 07.JavaMail.remedy(a)happy.test.com>, proto=ESMTP, daemon=MTA, > relay=happy.test.com [12.13.2.24] > Mar 16 05:48:30 mta-rwc-1.test.com sm-mta[15538]: [ID 801593 > mail.info] m2GCm3bI015538: from=<gremedyautoreply(a)test.com>, size=760, > class=0, nrcpts=1, > msgid=<14341520.1205671710508.JavaMail.remedy(a)happy.test.com>, > proto=ESMTP, daemon=MTA, relay=happy.test.com [128.137.26.24] Mar 16 > 05:48:30 mta-rwc-1.test.com sm-mta[15538]: [ID 801593 mail.info] > m2GCm3bJ015538: from=<gremedyautoreply(a)test.com>, size=755, class=0, > nrcpts=1, > msgid=<18840257.1205671710729.JavaMail.remedy(a)happy.test.com>, > proto=ESMTP, daemon=MTA, relay=happy.test.com [12.13.26.24] It looks like a sendmail log. If so, the first line should start with a timestamp, and it starts with "07.JavaMail.remedy(a)happy.test.com>" That makes it very hard to test to see if things works properly because you did not give us a correct input sample. I think the sample input is Mar 16 05:48:30 mta-rwc-1.test.com sm-mta[15538]: [ID 801593 mail.info] m2GCm3bI015538: from=<gremedyautoreply(a)test.com>, size=760, class=0, nrcpts=1, msgid=<14341520.1205671710508.JavaMail.remedy(a)happy.test.com>, proto=ESMTP, daemon=MTA, relay=happy.test.com [128.137.26.24] Mar 16 05:48:30 mta-rwc-1.test.com sm-mta[15538]: [ID 801593 mail.info] m2GCm3bJ015538: from=<gremedyautoreply(a)test.com>, size=755, class=0, nrcpts=1, msgid=<18840257.1205671710729.JavaMail.remedy(a)happy.test.com>, proto=ESMTP, daemon=MTA, relay=happy.test.com [12.13.26.24]
From: Maxwell Lol on 29 Mar 2008 06:25 explor <bhaveshah(a)gmail.com> writes: > #/bin/ksh > SIZE1=20971520 > for i in `grep "size=" $LOG | awk '{print $11}' | awk -F= '{print $2}' > | sed 's/\,//'` > do The sample input you provided does not contain any examples of the string "size=" so it very hard to debug your script.
From: Maxwell Lol on 29 Mar 2008 07:09 explor <bhaveshah(a)gmail.com> writes: > Hi Gurus, > > I've a log file which looks like below. I need help with the grep from > each line if the condition is met for the line. .e.g. size > 20 MB > then grep for msgid= for that line. > > The script which i am running doesn't give me the megid but instead > dumps the entire file. > > #/bin/ksh > SIZE1=20971520 [snip] !/bin/sh awk ' BEGIN { SIZE=20971520} $8 ~ /size=/ && $11 ~ /msgid=/ { # the size= field is $8, and msgid == $11 split($8,size,/[=,]/); split($11,msgid,/[=,]/); if (size[2]>=SIZE) { print msgid[2]; } } ' <$LOG
From: pk on 29 Mar 2008 08:30 explor wrote: > I've a log file which looks like below. I need help with the grep from > each line if the condition is met for the line. .e.g. size > 20 MB > then grep for msgid= for that line. >[cut] > > Mar 16 05:48:30 mta-rwc-1.test.com sm-mta[15538]: [ID 801593 > mail.info] m2GCm3bI015538: from=<gremedyautoreply(a)test.com>, size=760, > class=0, nrcpts=1, > msgid=<14341520.1205671710508.JavaMail.remedy(a)happy.test.com>, > proto=ESMTP, daemon=MTA, relay=happy.test.com [128.137.26.24] > Mar 16 05:48:30 mta-rwc-1.test.com sm-mta[15538]: [ID 801593 mail.info] > m2GCm3bJ015538: from=<gremedyautoreply(a)test.com>, size=755, class=0, > nrcpts=1, msgid=<18840257.1205671710729.JavaMail.remedy(a)happy.test.com>, > proto=ESMTP, daemon=MTA, relay=happy.test.com [12.13.26.24] (assuming that each line starts with the date, that all fields are always present and always come in the order you show) awk -F, '(substr($2,index($2,"=")+1)+0)>20971520 {print substr($5,index($5,"=")+1)}' file.txt -- All the commands are tested with bash and GNU tools, so they may use nonstandard features. I try to mention when something is nonstandard (if I'm aware of that), but I may miss something. Corrections are welcome.
From: Ed Morton on 31 Mar 2008 17:22
On 3/31/2008 1:07 PM, explor wrote: > On Mar 29, 3:25 am, Maxwell Lol <nos...(a)com.invalid> wrote: > >>explor <bhaves...(a)gmail.com> writes: >> >>>#/bin/ksh >>>SIZE1=20971520 >>>for i in `grep "size=" $LOG | awk '{print $11}' | awk -F= '{print $2}' >>>| sed 's/\,//'` >>>do >> >>The sample input you provided does not contain any examples of the >>string "size=" so it very hard to debug your script. > > > Sorry, Here is the correct log output: > > Mar 16 03:44:34 mta-rwc-1.test.com sm-mta[23527]: [ID 801593 > mail.info] m2GAiBIa023527: from=<gremedyautoreply(a)test.com>, size=754, > class=0, nrcpts=1, > msgid=<22271029.1205664274109.JavaMail.remedy(a)happy.test.com>, > proto=ESMTP, daemon=MTA, relay=happy.test.com [12.13.26.24] It's hard to tell with the snipping and line-wrapping so far but ssuming the above is all on one line, and that you're trying to extract "<22271029.1205664274109.JavaMail.remedy(a)happy.test.com>" fromt the msgid= field based on the value in the "size=<value>" field being greater than 20971520, and the msgid= field comes after the size= field then this should do it: awk -F, '{ size=msgid=0 for (i=1;i<=NF;i++) { if ($i ~ /size=/) { split($i,tmpA,"=") size=tmpA[2] } else if ($i ~ /msgid=/) { if (size > 20971520) { split($i,tmpA,"=") print tmpA[2] } } } }' file If that doesn't do what you want, tell us again what you want and provide some sample input (without line-wrapping) and THE output you expect FROM THAT INPUT. Ed. |