#! /bin/bash while read x do echo $x echo $x | cut -d_ -f2 | egrep -q "20[0-9]{2}(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])" [ $? -eq 0 ] && echo "Start date - correct format" || echo "Start date - not correct format" echo $x | cut -d_ -f3 | egrep -q "20[0-9]{2}(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])" [ $? -eq 0 ] && echo "End date - correct format" || echo "End date - not correct format" echo done < inputfile
while IFS='_' read v1 v2 v3 do echo $v1 $v2 $v3 done < infile