Hi All,
Wasted enough time on this so hopefully someone can tell where I'm going wrong here. Such a simple problem, but it's doing my head in!
I'm catching some data into variable VAR, looking to see if it contains (fc1) .. if so echo string and do something else if matches it.
I've tried both a 'for SRCH in file', and a 'while read SRCH' method here, both giving me headaches.
Main code:
Output:
Hope the above is clear enough. Will try pick up any advise you offer on the weekend or Monday even.
Thanks!
Wasted enough time on this so hopefully someone can tell where I'm going wrong here. Such a simple problem, but it's doing my head in!
I'm catching some data into variable VAR, looking to see if it contains (fc1) .. if so echo string and do something else if matches it.
I've tried both a 'for SRCH in file', and a 'while read SRCH' method here, both giving me headaches.
Main code:
Code:
VAR=`grep file.txt $SRCH | awk '{print $NF}'`
echo "var - $VAR" # Test line
#I even tried the bellow to strip the () and any blanks I can't see off in case that was the problem:
BVAR=`echo "$VAR" | sed -s 's/(//' | sed -s 's/)//' | sed -s 's/ //' `
echo "bvar - $BVAR" # Test line
if [ $BVAR = "fc1" ] # Or without the sed stripping above, if it sees (fc1) then do whatever next
then
echo "Working!"
VAR=`dosomething_else`
fi
echo "$SRCH,$VAR"
Output:
Code:
var - (fc1)
bvar - fc1
LINE1,(fc1)
var - (fc1)
bvar - fc1
LINE2,(fc1)
var - (fc1)
bvar - fc1
LINE3,(fc1)
var - (fc1)
bvar - fc1
LINE4,(fc1)
Hope the above is clear enough. Will try pick up any advise you offer on the weekend or Monday even.
Thanks!