码迷,mamicode.com
首页 > 系统相关 > 详细

Linux下生提取一年中的周一和周日

时间:2016-02-16 15:06:15      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:linux 获取一年中的所有周一 周日

#!/bin/bash

##############################

_Green="\033[32;1m"

_Red="\033[31;1m"

_End="\033[0m"

##############################

Server_Lang="`echo "${LANG}"`"

Search_Time="`date +%Y%m%d%H%M%S`"

##############################

echo -e "${_Green}The System Default Language: ${Server_Lang} ${_End}"

while ((1==1))

do

    read -p "Enter the year you want to query ! :" Query_Year

    if [[ "${Query_Year}" =~ ^[1-9][0-9]{0,3}$ ]]

    then

        for i in `seq -w 1 1 12`

        do

            Query_Re_Mon="`/usr/bin/cal -m ${i} ${Query_Year} | /usr/bin/sed -n ‘3,${/^$/d;p}‘ | /usr/bin/awk -F‘ ‘ ‘$0 !~ /^  /{printf "‘${Query_Year}‘-‘${i}‘-%02d\n",$1}‘`"

            echo "${Query_Re_Mon}" >> /tmp/.SM${Search_Time}

            Query_Re_Sun="`/usr/bin/cal -s ${i} ${Query_Year} | /usr/bin/sed -n ‘3,${/^$/d;p}‘ | /usr/bin/awk -F‘ ‘ ‘$0 !~ /^  /{printf "‘${Query_Year}‘-‘${i}‘-%02d\n",$1}‘`"

            echo "${Query_Re_Sun}" >> /tmp/.SS${Search_Time}

        done

        /usr/bin/paste /tmp/.SM${Search_Time} /tmp/.SS${Search_Time} >> /tmp/.QS${Search_Time}.xls

        /usr/bin/awk ‘BEGIN{printf "%10s\t%10s\n","Monday","Sunday"}{printf "%10s\t%10s\n",$1,$2}‘ /tmp/.QS${Search_Time}.xls >> /tmp/QS${Search_Time}.xls

        if [ -s "/tmp/QS${Search_Time}.xls" ]

        then 

            echo -e "${_Green}File saved in:/tmp/QS${Search_Time}.xls ${_End}"

        else

            echo -e "${_Red}File saved False ${_End}"

        fi

        exit

    else

        echo -e "${_Red} Input erro ${_End}"

        continue

    fi

done

   


本文出自 “工作经验” 博客,请务必保留此出处http://chlipeng.blog.51cto.com/8928892/1742424

Linux下生提取一年中的周一和周日

标签:linux 获取一年中的所有周一 周日

原文地址:http://chlipeng.blog.51cto.com/8928892/1742424

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!