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 :
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
Post a Comment