免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6881 | 回复: 59
打印 上一主题 下一主题

help! please simplify this shell program! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-07-10 08:43 |只看该作者 |倒序浏览
#!/usr/bin/ksh

case $# in
      0) year='date | awk '{print $6}'';;
      [1-9]*([0-9])) year=$1
          if ((year<1)) || ((year>9999))
          then
          echo "year must be 1 to 9999"
          exit 1
          fi;;
esac


# initialize variables
Mon=0 Tue=0 Wed=0 Thu=0 Fri=0 Sat=0 Sun=0

for count in 1 2 3 4 5 6 7 8 9 10 11 12
do
    if [ "'cal $count $year | sed -n '3p' | awk '/^ 1/{print}''" !=""]
    then Sun='expr $sun + 1'
    fi

    if [ "'cal $count $year | sed -n '3p' | awk '/^    1/{print}''" !=""]
    then Mon='expr $Mon + 1'
    fi

    if [ "'cal $count $year | sed -n '3p' | awk '/^       1/{print}''" !=""]
    then Tue='expr $Tue + 1'
    fi

    if [ "'cal $count $year | sed -n '3p' | awk '/^          1/{print}''" !=""]
    then Wed='expr $Wed + 1'
    fi
   
    if [ "'cal $count $year | sed -n '3p' | awk '/^             1/{print}''" !=""]
    then Thu='expr $Thu + 1'
    fi

    if [ "'cal $count $year | sed -n '3p' | awk '/^                1/{print}''" !=""]
    then Fri='expr $Fri + 1'
    fi

    if [ "'cal $count $year | sed -n '3p' | awk '/^                   1/{print}''" !=""]
    then Sat='expr $Sat + 1'
    fi
done

echo "Sunday $Sun\nMonday $Mon\nTuesday $Tue\nWednesday $Wed\nThursday $Thu\nFriday $Fri\nsaturday $Sat |Sort +1 -n |sed -n '7p' | awk '{print $1}'

论坛徽章:
0
2 [报告]
发表于 2003-07-10 09:08 |只看该作者

help! please simplify this shell program!

完成的是什么功能啊?

最起码几个if then.....fi可以合并到一起.

论坛徽章:
0
3 [报告]
发表于 2003-07-10 09:15 |只看该作者

help! please simplify this shell program!

a program to report the weekday that occurs to be the first day of the month most often within a given year

论坛徽章:
0
4 [报告]
发表于 2003-07-10 09:22 |只看该作者

help! please simplify this shell program!

Actually, these if and then are different,

awk '/^ (one space between)1/{print}''" !=""]  for sunday

awk '/^ (3 space between)1/{print}''" !=""]  for Monday

and so on,

I just want to extract a line which match to day 1 and also tell me what weekday it is.





#!/usr/bin/ksh

case $# in
      0) year='date | awk '{print $6}'';;
      [1-9]*([0-9])) year=$1
          if ((year<1)) || ((year>9999))
          then
          echo "year must be 1 to 9999"
          exit 1
          fi;;
esac


# initialize variables
Mon=0 Tue=0 Wed=0 Thu=0 Fri=0 Sat=0 Sun=0

for count in 1 2 3 4 5 6 7 8 9 10 11 12
do
    if [ "'cal $count $year | sed -n '3p' | awk '/^ 1/{print}''" !=""]
    then Sun='expr $sun + 1'
    fi

    if [ "'cal $count $year | sed -n '3p' | awk '/^    1/{print}''" !=""]
    then Mon='expr $Mon + 1'
    fi

    if [ "'cal $count $year | sed -n '3p' | awk '/^       1/{print}''" !=""]
    then Tue='expr $Tue + 1'
    fi

    if [ "'cal $count $year | sed -n '3p' | awk '/^          1/{print}''" !=""]
    then Wed='expr $Wed + 1'
    fi
   
    if [ "'cal $count $year | sed -n '3p' | awk '/^             1/{print}''" !=""]
    then Thu='expr $Thu + 1'
    fi

    if [ "'cal $count $year | sed -n '3p' | awk '/^                1/{print}''" !=""]
    then Fri='expr $Fri + 1'
    fi

    if [ "'cal $count $year | sed -n '3p' | awk '/^                   1/{print}''" !=""]
    then Sat='expr $Sat + 1'
    fi
done

echo "Sunday $Sun\nMonday $Mon\nTuesday $Tue\nWednesday $Wed\nThursday $Thu\nFriday $Fri\nsaturday $Sat |Sort +1 -n |sed -n '7p' | awk '{print $1}'

论坛徽章:
0
5 [报告]
发表于 2003-07-10 09:33 |只看该作者

help! please simplify this shell program!

是不是你的空格又被系统吃啦!你可以把你的代码写在

  1. 代码
复制代码

这样就能看到完整的格式啦.

你能用中文说明程序的目的吗?

论坛徽章:
0
6 [报告]
发表于 2003-07-10 22:49 |只看该作者

help! please simplify this shell program!

I don't know how to input Chinese in my computer.

I guess your guys are expert and it is a piece of cake to you.

论坛徽章:
0
7 [报告]
发表于 2003-07-10 23:22 |只看该作者

help! please simplify this shell program!

原帖由 "acific Yan" 发表:
I don't know how to input Chinese in my computer.

I guess your guys are expert and it is a piece of cake to you.
   
Then use another computer, show your respects to Gurus....

论坛徽章:
0
8 [报告]
发表于 2003-07-10 23:30 |只看该作者

help! please simplify this shell program!

Sorry, guys, I am not trying to offend anybody.  Tell you truth, I don't know how to input Chinese at all even you can offer me a good Chinese software.  My poor China Countryside education system

论坛徽章:
0
9 [报告]
发表于 2003-07-10 23:47 |只看该作者

help! please simplify this shell program!

是不是报告指定年份的每个月的第一天是星期几的程式啊?

论坛徽章:
0
10 [报告]
发表于 2003-07-10 23:57 |只看该作者

help! please simplify this shell program!

yes, you are really good! By the way, I am a bioinformatics and a biologist, and I am not a good programmer.  So, I am trying to learn something.  Also, do your guys have any any idea want to do something related to that area in China?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP