每天一个小练习--使用awk判断闰年

   使用awk判断闰年。(能被4整除但不能被100整除、能被400整除为闰年。)

# cat year.txt

1982

1985

2012

2003

3000

1200

1717

1869

1997

1999


# cat leap_year.txt

#! /bin/bash
# leap_year.awk
BEGIN {
  print "pick leap yers:"
}
{
year=$1
  if(( year %4 == 0 && year %100 != 0 ) || year %400 == 0)
        print year " is a leap year."
  else
        print year " is not a leap yesr."
}


# awk -f leap_year.txt year.txt

pick leap yers:

1982 is not a leap yesr.

1985 is not a leap yesr.

2012 is a leap year.

2003 is not a leap yesr.

3000 is not a leap yesr.

1200 is a leap year.

1717 is not a leap yesr.

1869 is not a leap yesr.

1997 is not a leap yesr.

1999 is not a leap yesr.


你可能感兴趣的:(awk,闰年)