Hello I have the below awk in my script . The regex pattern is not working correctly for me .I wanted to validate the email address which can have characters [a-z],[0-9] ,[.] ,@
code
here are the sample email patterns in the input file
1.abc@gmail.com
2.abc123@hotmail.com
3.abc.xyz@yahoo.com
4.a1@gmail.net
5.a2@xcom.in
the pattern is extracted from a metadata file and passed as a script paramter .here is the metadata line defines the pattern for email id validation
1~4~~~char~Y~\"\@\.com\"~100
sh -x run for the script code
val=$(
awk -F ,
-v n=4
-v 'm="*@*.com"'
-v count=0
'NR!=1 && $n !~ "^" m "$"
{
printf "%s:%s:%s\n", FILENAME, FNR, $0 > "/dev/stderr"
count++
}
END {print count}' BNC.csv
vi of the script code
val=$(awk -F "$sep"
-v n="$col_pos"
-v m="$col_patt"
-v count=0
'NR!=1 && $n !~ "^" m "$"
{
printf "%s:%s:%s\n", FILENAME, FNR, $0 > "/dev/stderr"
count++
}
END {print count}' $input_file
*@*.com
is a valid regex, it probably doesn't do what you expect. See How do regular expressions differ from wildcards used to filter files – steeldriver May 20 '21 at 18:29NR!=1 && $n !~ "^" m "$"
) and associated action ({ printf ... }
) matter. Please see the example I provided for you previously for one of the few common, legible ways to format your code or, again, just run it throughgawk -o-
and gawk will format it for you. Also, copy/paste your code into http://shellcheck.net and it'll tell you about the shell errors in it. – Ed Morton May 20 '21 at 23:08