Jan 28, 2002 #1 lutech Programmer Jan 25, 2002 16 CA If I have a date like 2002-04-20, how can I get the weekday of the day using shell script? Thanks in advance,
If I have a date like 2002-04-20, how can I get the weekday of the day using shell script? Thanks in advance,
Jan 29, 2002 #2 omari Technical User Jan 16, 2002 9 US Hi lutech , Here is just a sample . You have to copy the following script below into a file . Then execute the file . Sample Script begins as shown below : # !/bin/ksh echo " Week of the Month Computation " echo " ====================== \n" echo "Enter the Year-Month-Date format :\c" read user_input # Variables Year_value=`echo ${user_input} | cut -d"-" -f1,1 ` Month_value=`echo ${user_input} |cut -d"-" -f2,2 ` Date_value=`echo ${user_input} |cut -d"-" -f3,3 ` # Call calendar cal ${Month_value} ${Year_value} | grep -v -i [a-z] > tmp1 echo "week_1 week_2 week_3 week_4 week_5 " > tmp2 wk=`paste tmp2 tmp1 | grep ${Date_value} | awk -F" " '{print $1}' ` # Cleanup temporary files if [ -f tmp1 -a -f tmp2 ] then rm tmp1 tmp2 ; fi # Output to user echo " The week for ${user_input} shall be ${wk} " #Rgds , omari Upvote 0 Downvote
Hi lutech , Here is just a sample . You have to copy the following script below into a file . Then execute the file . Sample Script begins as shown below : # !/bin/ksh echo " Week of the Month Computation " echo " ====================== \n" echo "Enter the Year-Month-Date format :\c" read user_input # Variables Year_value=`echo ${user_input} | cut -d"-" -f1,1 ` Month_value=`echo ${user_input} |cut -d"-" -f2,2 ` Date_value=`echo ${user_input} |cut -d"-" -f3,3 ` # Call calendar cal ${Month_value} ${Year_value} | grep -v -i [a-z] > tmp1 echo "week_1 week_2 week_3 week_4 week_5 " > tmp2 wk=`paste tmp2 tmp1 | grep ${Date_value} | awk -F" " '{print $1}' ` # Cleanup temporary files if [ -f tmp1 -a -f tmp2 ] then rm tmp1 tmp2 ; fi # Output to user echo " The week for ${user_input} shall be ${wk} " #Rgds , omari