[root@localhost ~]# cat a.log a ab abc ddd [root@localhost ~]# [root@localhost ~]# cat b.log a ab abc ddd dd f [root@localhost ~]# [root@localhost ~]# sh 1.sh diff_list=dd f [root@localhost ~]# cat 1.sh my_tbs=(`cat a.log`) # my_tbs all_tbs=(`cat b.log`) # all_tbs declare -a diff_list t=0 flag=0 for i in "${all_tbs[@]}" do for j in "${my_tbs[@]}" do if [[ "${i}" == "${j}" ]]; then flag=1 break fi done if [[ $flag -eq 0 ]]; then diff_list[t]=$i t=$((t+1)) else flag=0 fi done echo diff_list=${diff_list[@]}