Hi,
My requirement is to check wheather some csv files have mandatory columns value as empty if empty log a error message or set a flag.
The problem here is that the column number varies for different CSVs hence we can not hardcode $1 or $3 like this in the awk command hence we are reading a proprty file to get the mandatory fields & then setting it to a variable by prefixing $ to that column number & checking the empty value for that column.
I am writing the following awk command :
Code:
for file in $run_count"_"*.csv; do
echo "file name "$file
PROP_KEY=$file
Property_Value=""
Property_Value=$(cat ${PROPERTY_FILE_NAME} | grep "${PROP_KEY}" | cut -d'=' -f2)
echo $Property_Value
OFIS=$IFS
IFS=','
array=$Property_Value
flag=""
for x in $array
do
COL_NUMBER="$""$x"
echo "COL numbr-"$COL_NUMBER
flag=$(awk -F"|" '{ if( '$COL_NUMBER' ~ /^ *$/ ){ printf("1"); }}' $file )
done
echo "flag = "$flag
var=$(echo $flag | cut -c1)
echo "var= " $var
if [ "$var" == "1" ]; then
echo "\n error encounterd in file" $file
exitFlag=1
else
echo "Successful"
fi
done
It works well in ksh shell of Unix but in AIX it fails with error :
Code:
Syntax Error The source line is 1.
The error context is
<<< { if( >>> $1
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.
Syntax Error The source line is 1.
Then we found out that '{ if( ' is creating problem as AIX is treating this as command for awk if I can get a solution to retreive the $COL_NUMBER as $1 then my problem will be solved. as $COL_NUMBER contains $1 or $2 something like this.
Any help will be appreciated
Thanks & Regards,
Sukhi