Hi,
I have come across a little strange problem in my script. i tried the same logic in some other script where its working fine. but in other script its not behaving as expected.
Here is the code:
Code:
#!/bin/bash
run_count="2"
catalog_name="demo"
cd /root/Test_project/Files/$catalog_name
for file in $run_count"_"*.csv; do
echo $file
file_count=`grep -c "." $file`
echo $file_count"file_count \n"
FILE_NAME=$run_count"_"$catalog_name"_Row_Count.prop"
PROP_KEY=$file
Count_file=$(awk -F"=" '{ ()print $1; }' $FILE_NAME )
echo "file count= "$Count_file
Count=`cat ${FILE_NAME} | grep ${PROP_KEY} | cut -d'=' -f2`
echo $Count #[Here its working fine, its showing the correct values which is returned from top]
echo $Count"hi" #[here if i'm printing something with it then the value of $Count is lost. and its only printing hi] don't know why
#and based on that furhter logic is not working which is under if
if [ "$Count" == "$file_count" ]; then
echo "column header count row proper"
else
echo "Error send a mail as count is not correct in "$file
exit 1
fi
done
exit 0
My question is this
1. Why the value is lost of $Count when am trying to print something with it.
2. Is there any problem of data type?
3. What type of datatype is returned by cut command in above?
Here I need to return integer and then to compare them
Count is the number of files, which is specified in a property file from where its picking in above case.
file_count is number of rows in a file.
I need to compare them both and then have to take action further.
Help me out if there is something wrong with data type or logic or something else.
Thanks,