我们需要比较数据类型。我创建了带有数据类型的 .txt 文件,并编写了一个查询以从 netezza 系统表(我们使用 netezza 数据库)获取数据类型并导出到 .TXT 文件。我已经使用diff -q
命令来突出显示是否有任何不匹配。实际上,每当匹配时我都会得到正确的结果,但如果有任何不匹配,它不会突出显示。我可能错过了给出正确的回显错误消息或其他内容以按预期获得。总共需要检查 10 个文件,因此我使用了 for 循环。
我尝试了下面的代码,但如果您有任何简单的逻辑或任何见解都会有所帮助。
for <condition>
do
TABLE_ddl="SELECT TYPE_NAME FROM SYSTEM.._V_SYS_COLUMNS WHERE TABLE_NAME = '${TABLENAME}name';
echo ${TABLE_ddl};
CURRENT_TEMP_DDL=`nzsql -h ${hostname} -db ${database} -u ${username} -pw ${password} -A -t -o ${PATH}/${TABLENAME}_TABLE.TXT -c "${TABLE_ddl}"`
echo ${CURRENT_TABLE_DDL};
done
CHECK=`diff -q ${PATH}/${TABLENAME}_FILE.txt ${PATH}/${TABLENAME}_TABLE.TXT`;
我期待如下的输出。
tablename
CURRENT_TEMP_DDL #Query which should reflect with table name
datatypes matched
For ex.
employee
select type_name from system.._v_sys_columns where table_name = 'employee' and database =<dbname>
datatypes matched for employee_FILE.txt and employee_TABLE.TXT
department
select type_name from system.._v_sys_columns where table_name = 'department' and database =<dbname>
datatypes unmatched for department_FILE.txt and department_TABLE.TXT
答案1
我不确定“突出显示”两个文件的差异到底是什么意思,但您可以用来diff
显示两个文件的差异:
diff file1 file2 | grep "<" | sed 's/^<//g'
显示到标准输出
其结果为:
skywalker@endor:~/scripts/python/proxyupdate$ diff proxyupdate.py proxyupdate.bak | grep "<" | sed 's/^<//g'
#this line is added for testing
或者
diff file1 file2 | grep "<" | sed 's/^<//g' > file3.txt
写入新文件。
或者你也可以尝试sort
:
sort file1 file2 | uniq -u
产生相同的结果:
skywalker@endor:~/scripts/python/proxyupdate$ sort proxyupdate.py proxyupdate.bak | uniq -u
#this line is added for testing