I need to check delimiter '|' count for each line in text file for that used awk command and stored count of output file in temp file. It was generating count of delimiter for each row and script also finally I can see success with exit code 0. but in one of the line it was showing arithmetic syntax error could some one tell me how to resolve this.
I provided sample filedata, script and script output could someone tell me what was the issue here for arithmetic syntax error.
Text file Sample data: in below sample file there were 5 '|' delimiter and some sample rows
Name|Address|phone|pincode|location|
xyz|usa|123|111|NY|
abc|uk|123|222|LON|
pqr|asia|123|333|IND|
Script:
Standard_col_cnt="5"
cd /$SRC_FILE_PATH
touch temp.txt
col_cnt=`awk -F"|" '{print NF}' $SRC_FILE_PATH/temp.txt` >>$Logfile 2>&1
while read line
do
i=1
echo $line >/temp.txt
if [ "$col_cnt" -ne "$Standard_col_cnt" ]
then
echo "No of columns are not equal to the standard value in Line no - $i:" >>$Logfile
exit 1
fi
i=`expr $i + 1`
done < $File_name
Awk command will generate below output to temp file:
5
5
5
5
--------- Script output -----------
script.sh[59]: [: |xyz|usa|123|111|NY|
: arithmetic syntax error
+ expr 1 + 1
+ i=2
+ read line
+ i=1
+ echo 'xyz|usa|123|111|NY|\r'
+ script.sh[48]: /temp.txt: cannot create [Permission denied]
+ 'abc|uk|123|222|LON|\r' -ne 91 ]
script.sh[59]: [: pqr|asia|123|333|IND|: arithmetic syntax error