0

We have a requirement to compare the datatypes. I have created .txt files with datatypes and wrote a query to get the datatypes from the netezza system table (we are using netezza database) and exporting in to .TXT file. And i have used diff -q command to highlight if there are any mismatches. Actually i am getting correct results whenever it is matching but it is not highlighting if there are any mismatches. I might missed to give a correct echo error messages or something else to get as expected.Total 10 files needs to be checked so i have used for loop.

I tried below code, but if you have any simple logic or any insights would be helpful.

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`;

And i am expecting an output like below.

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 Answer 1

0

I'm not sure what you mean exactly by "highlighting" the difference of the two files, but you can use diff to display the differences of the two files:

diff file1 file2 | grep "<" | sed 's/^<//g' to display to stdout

which will produce the result:

skywalker@endor:~/scripts/python/proxyupdate$ diff proxyupdate.py proxyupdate.bak | grep "<" | sed 's/^<//g'
 #this line is added for testing

or

diff file1 file2 | grep "<" | sed 's/^<//g' > file3.txt to write to a new file.

or you can also try sort:

sort file1 file2 | uniq -u

which produces the same result:

skywalker@endor:~/scripts/python/proxyupdate$ sort proxyupdate.py proxyupdate.bak | uniq -u
#this line is added for testing
1
  • Thanks for your Inputs and sorry for late reply. I got the desired result by using cmp command.
    – Samah
    Apr 13, 2017 at 9:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .