#!/bin/bash
line_src=`cat check.ctpsp_gk.sql|wc -l`
line_dest=`cat check.ctpsp_gk.txt|wc -l`
rm -rf sql_result.txt
rm -rf data_result.txt
touch sql_result.txt
touch data_result.txt
echo $line_src
echo $line_dest
for ((i=1,j=1;i<=$line_src&&j<=$line_dest;i++));
do
source_sql=`awk 'NR=='"$i"'{print $0}' check.ctpsp_gk.sql`
dest_data=`awk 'NR=='"$j"'{print $0}' check.ctpsp_gk.txt`
tab_name=`awk 'NR=='"$j"'{print $1}' check.ctpsp_gk.txt`
tab_count=`awk 'NR=='"$j"'{print $2}' check.ctpsp_gk.txt`
src_tab_name=`echo $source_sql | sed "s/.*'\(.*\)'.*/\1/"`
if [ "$src_tab_name" == "$tab_name" ] && [ $tab_count -lt 1000000 ];then
echo $source_sql >> sql_result.txt
echo $dest_data >> data_result.txt
let j++;
elif [ "$src_tab_name" == "$tab_name" ] && [ $tab_count -ge 1000000 ];then
let j++;
fi
echo "$source_sql"
echo "$dest_data"
echo "i=$i j=$j"
#echo "i=$i $source_sql"
#echo "$src_tab_name"
done
运用到以下知识点:
--匹配出单引号中的字符
echo "select 'ie_bidsection',count(*) from ctpsp.ie_bidsection" | sed "s/.*'\(.*\)'.*/\1/"
--if下变量和数字比对
--lt < le <= gt > ge >= ne <> eq =
if [ "$src_tab_name" == "$tab_name" ] && [ $tab_count -lt 1000000 ];then
elif [ "$src_tab_name" == "$tab_name" ] && [ $tab_count -ge 1000000 ];then
fi
--变量自增
a=$(($a+1))
a=$[$a+1]
a=`expr $a + 1`
let a++
let a+=1
((a++))