Unix字符串比较

时间:2015-12-15 19:34:34

标签: string unix hive comparison impala

我有两个变量用不同的方法填充,我想要比较它们的值。如果您注意到下面的回声,则两个变量值都相同,但字符串比较表示"不匹配"。可能有什么不对?

代码:

IMPALA_NODE=ipaddress.goes.here  
HIVE_DBNAME="dbname"  
HIVE_TABLENAME="tablename"  
CNT_FILE=$(wc -l < /tmp/filename.csv)  
CNT_EXTTABLE=`impala-shell -k -i $IMPALA_NODE -d $HIVE_DBNAME -q "select count(*)+1 from ${HIVE_TABLENAME};" --quiet -B -c`  
echo "_${CNT_FILE}_"  
echo "_${CNT_EXTTABLE}_"  
if [ "$CNT_EXTTABLE" = "20" ]; then  
echo "match"  
else  
echo "no match"  
fi  

输出继电器:
_20_
_20_
没有比赛

2 个答案:

答案 0 :(得分:1)

似乎imapala-shell在行中放置了某种控制字符,因此替代方法是将结果输出到文件然后读取它。看到这个链接: https://groups.google.com/a/cloudera.org/forum/#!topic/impala-user/_pSQtqPPke0

答案 1 :(得分:0)

您可以在比较中尝试“==”。 我还要在if语句的末尾添加'fi'。

x = [1,1,1]
print(set(x))
> {1}

%&gt; source test.sh

class MyClass(object):
   def __init__(self):
         self.mylist = []
   def train(self,vector):
         self.mylist.append(vector)
         self.mylist = list(set(self.mylist))