The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-16-2007
Registered User
 

Join Date: Aug 2006
Posts: 54
Awk ...

This is how my input file is .
< IM.OMNI #5.2.2 SMTP; 552 cq05c.my.corp.root: your "received:" header counts of 16 exceeds maximum setting 15>
adjsahdjas kasdks 91039 sdf
sdhsahsah dfkdsjf 23948 jfkdsljf
< IM.OMNI #3.2.2 SMTP; 552 cq05c.my.corp.root: your "received:" header counts of 16 exceeds maximum setting 15>
sdkjfkdsjfkdsljfksd
sdjfdkjfdksfj

I am trying the following :
/[[#][0-9][.][0-9][.][0-9]/
{
if ((/#4.4.6/) || (/#5.1.1/) || (/#5.2.2/) || (/#4.2.2/) || (/#5.2.1/))
{ valid_rec++; }
else
{invalid_rec++; }
}
But this is not giving me the correct count. invalid_rec is incremented for every word.
Increment must happen for every line.
Please guide.
I want the valid_rec = 1 and invalid_rec = 1. How do I achieve this with awk ?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-16-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
awk '
/[[#][0-9][.][0-9][.][0-9]/ { 
if( match ( $0 , "#4.4.6" ) || match( $0 , "#5.1.1" ) || match( $0 , "#5.2.2" ) || match( $0 , "#4.2.2" ) || match( $0 , "#5.2.1" )  )
	valid_rec++;
else
	invalid_rec++;
} 
END { print "valid=" valid_rec ",inv=" invalid_rec ; } ' file
Reply With Quote
  #3 (permalink)  
Old 02-20-2007
Registered User
 

Join Date: Aug 2006
Posts: 54
Hello

This is still counting words instead of the lines where the matched words are found.
Reply With Quote
  #4 (permalink)  
Old 02-20-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
I got valid record as one and invalid record as one with your sample data.Can you post some more sample data?
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:01 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0