1

How can I get day name like Friday Thursday from date string in SunOS 5.10 shell script. A user will input date in the format yyyymmdd (20130816) then I have to get day name?

Amith
  • 1,424
  • 1
  • 10
  • 22
Asad Ahmed
  • 11
  • 1

1 Answers1

0

To get the number of day in Week:

Update - A more complete script:

#!/bin/ksh

date="$1"
DAYMAP="0,SUNDAY\n1,MONDAY\n2,TUESDAY\n3,WEDNESDAY\n4,THURSDAY\n5,FRIDAY\n6,SATURDAY"
eval $(echo "${date}" | nawk -F- '{printf("year=%s month=%s day=%s\n", $1, $2, $3)}')


DAY=`cal "${month}" "${year}" | nawk -v day="${day}" '
  FNR > 2 {
    for(i=1; i <= NF; i++)
      if ( $i == day) {
        #printf("day->[%d] row->[%d]\n", $i, FNR-2)
        printf("%d\n", (NF == 7 || FNR!=3) ? i-1 : i+(6-NF))
        exit
      }
  }
'`

echo $DAYMAP | grep $DAY | cut -f2 -d','

Then use a map to print the full name of the day. Sunday is 0.

Input is in the format: 2013-08-16

dvai
  • 1,953
  • 3
  • 13
  • 15