-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshow_date
executable file
·63 lines (49 loc) · 1.62 KB
/
show_date
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
## $Id: show_date,v 1.3 2015/05/05 08:04:31 yozo Exp $
##
progname=`basename "$0"`
flag_debug=0
help(){
echo "usage: ${progname} messageID"
}
## main
case "$1" in
-h*)
help
exit 0
break
;;
-debug)
flag_debug=1
;;
esac
date_header=`sed '/^$/,$d' | sed -n 's/^[dD][aA][tT][eE]:[ ]*\(.*\)$/\1/p'`
if [ 1 -eq ${flag_debug} ]; then
echo "DEBUG: date_header == ${date_header}"
fi
## a typical date header looks like "Date: Mon, 13 Apr 2015 17:00:51 +0900"
## Day-of-Week Day-of-Month Month Year ...
## note that Day-of-Week is optional.
## dayom=`echo ${date_header} | awk '{print $2;}' | sed 's/^0*//'`
## month=`echo ${date_header} | awk '{print $3;}' \
dayom=`echo ${date_header} | sed -E 's/^(([a-zA-Z][a-zA-Z][a-zA-Z],)*[ \t]*(0?[1-9]|[12][0-9]|3[01])[ \t]*([a-zA-Z][a-zA-Z][a-zA-Z]).*)$/\3/' | sed 's/^0*//'`
if [ 1 -eq ${flag_debug} ]; then
echo "DEBUG: dayofm == ${dayom}"
fi
month=`echo ${date_header} | sed -E 's/^(([a-zA-Z][a-zA-Z][a-zA-Z],)*[ \t]*(0?[1-9]|[12][0-9]|3[01])[ \t]*([a-zA-Z][a-zA-Z][a-zA-Z]).*)$/\4/' \
| sed -e 's/[jJ][aA][nN]/1/' \
-e 's/[fF][eE][bB]/2/' \
-e 's/[mM][aA][rR]/3/' \
-e 's/[aA][pP][rR]/4/' \
-e 's/[mM][aA][yY]/5/' \
-e 's/[jJ][uU][nN]/6/' \
-e 's/[jJ][uU][lL]/7/' \
-e 's/[aA][uU][gG]/8/' \
-e 's/[sS][eE][pP]/9/' \
-e 's/[oO][cC][tT]/10/' \
-e 's/[nN][oO][vV]/11/' \
-e 's/[dD][eE][cC]/12/' `
if [ 1 -eq ${flag_debug} ]; then
echo "DEBUG: month == ${month}"
fi
printf "%02d/%02d" "${month}" "${dayom}"