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?
Asked
Active
Viewed 412 times
1

Amith
- 1,424
- 1
- 10
- 22

Asad Ahmed
- 11
- 1
-
I don't have SunOS right now, but can you try if this works for you? `date -d "20130816" +%A` – Kent Aug 16 '13 at 13:13
-
1@Kent unfortunately -d option does not work in SunOS 5.10 :( – dvai Aug 16 '13 at 13:21
1 Answers
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