Date validation

File contains below data,how to validate the date using awk command or any command.

date formate is fixed as "YYYYMMDD"

 test1|20120405
test2|20121405

output should be:

 test1|20120405

Thanks

A simple way is to use the touch command...

$ cat file1
test1|20120405
test2|20121405

$ while read ln; do dt=${ln#*|}"0000"; touch -t "$dt" testfile && echo "$ln"; done < file1 > file2
touch: invalid date format `201214050000'

$ cat file2
test1|20120405

$ rm testfile

$

Thanks lot.