Hi all,
I need another set of eyes and brains to explain why I can't get this working. If could be a simple case of bracket problems which always catch me out ;-)
I have a file called main.txt which I run the script against. The script is meant to check if certain lines of text appear in the file and perform a condition if they do. In this sample just a echo if good or bad really.
main.txt contains:
The data file contains the following lines of text which are the lines I need to look for:
This is what the script looks like:
This is the output when the script is run against it:
As you can see the output is not working too well... any idea why this is?
It seems my biggest headache might be because of the + sign, or with the way I'm doing the if checks...
Should I approach this in a total different way perhaps? I'm open to suggestions
Thanks
I need another set of eyes and brains to explain why I can't get this working. If could be a simple case of bracket problems which always catch me out ;-)
I have a file called main.txt which I run the script against. The script is meant to check if certain lines of text appear in the file and perform a condition if they do. In this sample just a echo if good or bad really.
main.txt contains:
Code:
100 bbb ccc 0 eee fff ggg+ hhh iii
100 bbb ccc 1 eee fff ggg+ hhh iii
100 bbb ccc 2 yyy fff ggg+ hhh iii
100 bbb ccc 3 eee fff ggg+ hhh iii
100 bbb ccc 1 eee fff ggg+ hhh ddd
100 bbb ccc 5 eee fff ggg+ hhh iii
100 bbb ccc 12 eee fff ggg+ hhh iii
100 xxx ccc 1 eee fff ggg+
100 xxx ccc 5 eee fff ggg+
100 xxx ccc 12 eee fff ggg+
The data file contains the following lines of text which are the lines I need to look for:
Code:
Pass,100 bbb ccc 1 eee fff ggg+ hhh iii,all,on
Pass,100 xxx ccc 5 eee fff ggg+,all,on
This is what the script looks like:
Code:
#!/usr/bin/bash
DATA="data2.csv"
while read LINE
do
STD=`echo $LINE | awk -F, '{print $2}'`
CHK=`grep -w "$STD" $1 `
echo "---------------- "
# Display if output is caught or not:
echo "STD = $STD"
echo "CHK = $CHK"
echo "---------------- "
if [ "$CHK" = "$STD" ]
then
echo " *** GOOD - $STD found ***"
elif [ "$CHK" = "" ]
then
echo " *** BAD - $STD not found ***"
fi
done < $DATA
This is the output when the script is run against it:
Code:
----------------
STD = 100 bbb ccc 1 eee fff ggg+ hhh iii
CHK = 100 bbb ccc 1 eee fff ggg+ hhh iii
----------------
*** GOOD - 100 bbb ccc 1 eee fff ggg+ hhh iii found ***
----------------
STD = 100 xxx ccc 5 eee fff ggg+
CHK =
----------------
*** BAD - 100 xxx ccc 5 eee fff ggg+ not found ***
As you can see the output is not working too well... any idea why this is?
It seems my biggest headache might be because of the + sign, or with the way I'm doing the if checks...
Should I approach this in a total different way perhaps? I'm open to suggestions
Thanks