#!/bin/bash
echo "Before grep"
grep -'.*' $1
echo 
"After grep"
grep -'^((((1[6-9]|[2-9][0-9])[0-9]{2})-(0?[13578]|1[02])-(0?[1-9]|[12][0-9]|3[01]))|(((1[6-9]|[2-9][0-9])[0-9]{2})-(0?[13456789]|1[012])-(0?[1-9]|[12][0-9]|30))|(((1[6-9]|[2-9][0-9])[0-9]{2})-0?2-(0?[1-9]|1[0-9]|2[0-8]))|(((1[6-9]|[2-9][0-9])(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$' $1
file文件:
2007-7-17
2007-07-17
2007-02-31
2007-1-21
1900-03-03
1988-03-4
1900-42-12
$./date.sh file
(输出)
Before grep
2007-7-17
2007-07-17
2007-02-31
2007-1-21
1900-03-03
1988-03-4
1900-42-12
After 
grep
2007-7-17
2007-07-17
2007-1-21
1900-03-03
1988-03-4