Sample Header Ad - 728x90

regex pattern issue for digit validation in ksh

0 votes
1 answer
632 views
I was writing a ksh script to validate the column is numerical. The regex pattern is defined in a config file like \d+.\d+. But this is not working when I use d pattern. However [0-9]{1,9} is working. Any insights into this? * Here is the ksh version I am using:
$ ksh --version
      version         sh (AT&T Research) 93u+ 2012-08-01
* Code snippet for the pattern comparison. If I provide $col_patt as \d+ it would not work but [0-9]{1,} will work
val=$(awk -F "$sep" -v n="$col_pos" -v m="$col_patt" 'NR!=1 && $n !~ "^" m "$" {
                             printf "%s:%s:%s\n", FILENAME, FNR, $n > "/dev/stderr"
                             count++
                           }
                           END {print count+0}' "$cp_input" 2>> $script_path/errors_${file_name_patt}.log
                           )
* Here is the pattern used: \d*\.\d+
Asked by daturm girl (49 rep)
Jun 15, 2021, 02:06 PM
Last activity: Jun 5, 2025, 05:16 PM