![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 ? |
| Forum Sponsor | ||
|
|
|
|||
|
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
|
| Thread Tools | |
| Display Modes | |
|
|