-rw-r--r-- 1 root root 28 Jul 13 15:00 a.txt
-rw-r--r-- 1 root root 30 Jul 13 15:00 b.txt
[root@localhost xly]# cat a.txt
hello
123
this is a.txt
456
[root@localhost xly]# cat b.txt
hello!
123
this is b.txt
4567
[root@localhost xly]# diff a.txt b.txt
1c1
< hello
---
> hello!
3,4c3,4
< this is a.txt
< 456
---
> this is b.txt
> 4567
1c1就是指2个文件第一行不一样
<指的是a.txt
>指的是b.txt
没明白你的意思,就写了一个判断两个文件对应行是不是相同。在线的话就追问我。line=`cat file1|wc -l`
for ((i=1i<=$linei++))do
file1=`awk 'NR="'$i'"{print $0}'` file1
file2=`awk 'NR="'$i'"{print $0}'` file2
if [ $file1 == $file2 ]then
echo line $i looks same!
else
echo line $i looks different!
fi
done
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)