bash - Linux shell script regex match -


i have text file. want lines starting specific format. want lines have x/x/x format. x number. regex not working. giving no match :

while read line                           regex="\d+\/\d+\/\d+"     if [[ ${line} =~  ${regex} ]];           echo ${line}      else          echo "no match : ${line}"      fi     done <${textfilename} 

file :

enter image description here

don't use bash if can use better tool:

grep -e '^[[:digit:]]+/[[:digit:]]+/[[:digit:]]+' "${textfilename}" 

but if have use bash:

while ifs= read -r line   if [[ "$line}" =~ ^[[:digit:]]+/[[:digit:]]+/[[:digit:]]+ ]];      echo -- "$line"   else     echo "no match: $line"   fi done < "$textfilename" 

\d not valid regex(3).


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

What is happening when Matlab is starting a "parallel pool"? -