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 -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -