I was trying to use an awk command to verify if a particular column is not matching with a regex (basically I am validating a column in a file with uniform format , if not I need to throw error)
format=$2
col_pos=$1
val= `awk -F "|’’ -v m="$format" -v n="$col_pos" '$n ~ "^"m"$"{print $1}' sample_file.txt`
if [[ $val != "" ]]; then
echo " column value is having unexpected format"
fi
sh sample.sh [a-z]{8}@gmail.com 3
Awk command is throwing an error. Can anybody help to correct the same?
Input file:
fileid|filename|contactemail
1|file1.txt|[email protected]
2|file2.txt|[email protected]
3|file3.txt|xyz -------->invalid column value as it doesnt satisfies the format @gmail.com
Here is the sample program run (expected to catch error as xyz is not a valid email)
$ sh sample.sh 3 [a-z]@gmail.com
$ sh -x sample.sh 3 [a-z]@gmail.com
+ format='[a-z]@gmail.com'
+ col_pos=3
++ awk -F '~' -v 'm=[a-z]@gmail.com' -v n=3 '$n ~ "^"m"$"{print $1}' sample_file.txt
+ val=
+ [[ '' != '' ]]