Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk recognizing even vs odd

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I need to determine if $2 is even or odd and then write out $0 to the appropriate even or odd .lis. What is the awk command that specifies this function. (modulator??)
 
Hi

Modulus is done with the operator %
so even is

if( $2 % 2 == 0 ){ ... } # even
else { ... } # odd

or odd is

if( $2 % 2 == 1 ){ ... }

Cheers,
ND
 
The operator for modulo is %

if ($2 % 2 == 0)
print $0 > even.lis
else
print $0 > odd.lis Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top