I have a bash script that has a filename and a string contained within a file and I want to compare a substring from the file against the filename(tar.gz) to see if they match or not.
substr=$(echo "$(cat /home/user/configrc | grep Version)" | cut -d '_' -f4-5) xfile="/home/user/data_1806_01.tar.gz" echo $substr echo $xfile echo "Is $substr in $xfile" if [ "$xfile" == *"$substr"* ]; then echo "Match"; else echo "No Match"; fi
the output is as follows
DD_DATA_AB_1806_01 1806_01 /home/user/data_1806_01.tar.gz in /home/user/data_1806_01.tar.gz No Match
I can't get a match to occur, 1806_01 should have the substring match in DD_DATA_AB_1806_01. Also what is strange is that the line - echo "Is $substr in $xfile" does not get printed out properly - "Is $substr" or "Is 1806_01" is missing
Is there some sort of termination that i need at the end of substr??
The file configrc contains the line Version=DD_DATA_AB_1806_01
I have looked at many examples online but can't see what I am doing wrong.... such a simple problem....
Thank you very much :)